top of page
Search
Writer's pictureKelson Wysocki

Spring/Summer Project - Update 8

Hello everyone. I have been slow to get back to working on this project the last few weeks, especially in making new things. My focus has been on improving the underlying systems to make the process of creating new content much easier, similar to what I talked about in my previous update.

Some Changes to Input

One of the big changes I made to the project since the last update was to use Unreal Engine's Enhanced Input System instead of the older, deprecated system. When I originally started this project I had no experience with this new input system and chose to stick with the system I knew but since then I have worked on another project where one of the goals was learning the new input system.


I have found this new input system makes working with player inputs much nicer than the previous version. For each input, an Input Action object gets created and this object defines what type of value the input will be and how this input gets triggered.


In this example, movement inputs will be taken as a Vector2D and will be triggered when an input key is down or released.


Once there are Input Action objects an Input Mapping Context must be created to define how those actions are used. In the case of movement W, A, S, and D are all valid keys but the context needs to do more information to guarantee the correct values are read, this is where Modifiers come in.


For movement having forward/backward and left/right inputs on different axis feels natural and this is what the Swizzle Input Axis Values modifier does. Now the X axis will contain left/right input information and the Y axis will contain the forward/backward information. The one last thing that must be done is to add the Negate modifier to one input for each axis, to differentiate between directions.




Once these are set up it is simple to bind actions in C++. All that is needed is to add both the Input Mapping Context and Input Actions to the player character header file.

Player Controller Header File

Then inside the SetupPlayerInputComponent function, you use the Input Action object to bind to a C++ function.


void ACPP_PlayerController::SetupPlayerInputComponent( UInputComponent *PlayerInputComponent ) {
    // Get the player controller
    APlayerController *pc = Cast< APlayerController >( GetController() );

    // Get the local player subsystem
    UEnhancedInputLocalPlayerSubsystem *Subsystem = ULocalPlayer::GetSubsystem< UEnhancedInputLocalPlayerSubsystem >( pc->GetLocalPlayer() );
    // Clear out existing mapping, and add our mapping
    Subsystem->ClearAllMappings();
    Subsystem->AddMappingContext( input_mapping, 0 );

    // Get the EnhancedInputComponent
    UEnhancedInputComponent *PEI = Cast< UEnhancedInputComponent >( PlayerInputComponent );

    // Bind the actions
    PEI->BindAction( input_move, ETriggerEvent::Triggered, this, &ACPP_PlayerController::Move );
}

What Next?

At this point, I have finished many of the changes to the existing systems that I had planned and will get back to making new content and focusing on improving the game.

24 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
Post: Blog2 Post
bottom of page