Announcement

Collapse
No announcement yet.

How would you add a custom movement component to a Character?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How would you add a custom movement component to a Character?

    I want to add a gliding capability to my character. I had a look at the character movement component and there is a option for custom movement https://docs.unrealengine.com/latest...ode/index.html but I have no idea how to integrate gliding with this.

    I would a create my own movement component which composes all my custom movement components
    Code:
    class MyCustomMovement{
       CharacterMovementComponent cm;
       GlidingMovementComponent gm;
       SlidingMovementComponent sm;
       ...
    };
    I am wondering if there is a better way to customize the CharacterMovementComponent?

    #2
    The CharacterMovementComponent already has a few different movement modes, Flying(simple), Swimming, Falling, Walking and most important for your needs Custom.

    You'll want to create a new class inheriting from CharacterMovementComponent. You call SetMovementMode(EMovementMode::Custom, MyUint8CustomMode) on the character movement component when you want to glide. That frees you of interference from the default modes. Override OnMovementModeChanged, check if it is your custom mode

    PHP Code:
    void UMyMovementComponent::OnMovementModeChanged(EMovementMode prevMovementuint8 prevCustomMovement)
    {
         
    Super::OnMovementModeChanged(prevMovement,PrevCustomMovement);

         
    //Should probably set up an enum cast to uint8 for checking against custom mode (uint8)EMyCustomMovement::GLIDE
         
    if(MovementMode==EMovementMode::Custom &&  CustomMovementMode == MyGlideUint8)
         {   
              
    //Set my glider settings
         
    }

    Download the glider project from the marketplace. It doesn't use a movement mode and is a blueprint project, but it has the basic physics down for gliding. It's called "Landscape Mountains"
    Last edited by james0x0A; 10-18-2014, 11:40 AM.

    Comment


      #3
      if you want to go the CUstomMovementComponent route you need to do the following:

      In your Character Class you need to add this to the constructor (BRS is the prefix I'm using for our project, you would need to insert your own class names instead of mine)

      Code:
      ABRSCharacter::ABRSCharacter(const class FPostConstructInitializeProperties& PCIP)
      	: Super(PCIP.SetDefaultSubobjectClass<UBRSCharacterMovementComp>(ACharacter::CharacterMovementComponentName))
      {
          // Other Stuff ...
      This will make the Character use your custom MovementComponent Class.

      One important function would be PhysCustom in CharacterMovementComponent. Override it and call your custom MovementPhysics from there:
      Code:
      void UBRSCharacterMovementComp::PhysCustom(float deltaTime, int32 Iterations)
      {
      	switch (CustomMovementMode)
      	{
      	case CMOVE_Slide:
      		PhysCustomSlide(deltaTime, Iterations);
      		break;
      	case CMOVE_Roll:
      		PhysCustomRoll(deltaTime, Iterations);
      		break;
      	case CMOVE_WallRun:
      		PhysCustomWallrun(deltaTime, Iterations);
      		break;
      	case CMOVE_WallClimb:
      		PhysCustomWallclimb(deltaTime, Iterations);
      		break;
      	case CMOVE_LedgeClimb:
      		PhysLedgeClimb(deltaTime, Iterations);
      		break;
      	case CMOVE_None:
      	default:
      		break;
      	}
      }
      This should be the important stuff.


      CMOVE_... where defined using #define to make the code more readable
      Last edited by Tomura; 10-18-2014, 01:08 PM.

      Comment


        #4
        How should I construct the Custom CharacterMovementComponent so that I can call its functions? To use the above example, how do I make sure PhysCustomSlide is being called if I call
        Code:
        GetCharacterMovement()->SetMovementMode(MOVE_Custom, CMOVE_Slide)
        Wouldn't that call the non-overridden member PhysCustom()?

        Comment

        Working...
        X