Enlightenment about MovementComponent?

Ok so i did as you did Fabrice but again like you my character is spinning like a top. I think im missing something. What did you do Fabrice for this?

For the moment : nothing. From my observations the CalcVelocity function take into account the Character Rotation to compute the Acceleration vector. Therefore, using this vector in the FaceRotation function make the bug we both have.

I have no solution, CalcVelocity seems to also decide what type of physics you have (falling/walking) so for the moment I’m waiting the new build has it will contain more in-depth explanation about some class (I hope).
At this point I’m unable to override so much functions without knowing what they really do.

I know how to coded it, but i dont know what the code is to make the player face the direction it is moving in. If you can tell me how you did it maybe in unrealscript i will try to code it here and show you. For example i know that you should you charactermovement->Acceleration for what you need but all that does is make my spin around.

In unrealscript is was very simple :

			if(P.Physics != PHYS_Falling)
			{
					NewAccel = PlayerInput.aForward*X + PlayerInput.aStrafe*Y;
					
				NewAccel.Z = 0;
			}
			
			
			//--------------------------------------------------------------------
			//--------------------------------------------------------------------
			//--------------------------------------------------------------------

			//apply mesh rotation smoothly
			OldRot = P.Rotation;
			if( P != None )
			{ 
				if(VSize(NewAccel) != 0.0)
					NewRot = Rotator(NewAccel);
				else
					NewRot = Pawn.Rotation;
			}
			
			if(P.bCamCinematic)
				Pawn.FaceRotation(RInterpTo(OldRot, NewRot, Deltatime, 60000, true), Deltatime);
			else
				Pawn.FaceRotation(RInterpTo(OldRot, NewRot, Deltatime, 100000, true), Deltatime);
				
			NewAccel = Pawn.AccelRate * Normal(NewAccel);

Reproducing this in Rocket doesn’t work because of what I mentioned just above.

This part here what function was it in

An override of the PlayerMove function inside the PlayerController State.

Ok wait i got an idea

As James mentioned this will be much easier in the upcoming beta (with bOrientToMovement). Until then I can shed some light on the basic approach to camera-relative movement (or orienting towards the movement direction) in the current code-base. This may help you find something that works in the meantime:

  • Set bUseControllerRotationYaw to false for the Character. This is done if you don’t want the character to rotate as you move the mouse/camera, since normally the UpdateRotation() call to FaceRotation() changes the Character’s rotation based on the ControlRotation of the PlayerController.

  • You are correct to drive the rotation by CharacterMovement->Acceleration. Orienting to the input direction is done by code something like this:

      // Turn acceleration direction into a rotation
      FRotator DesiredRotation = (Acceleration.SizeSquared() > 0.f ? Acceleration.SafeNormal().Rotation() : CurrentRotation);
      
      // Interp to desired rotation
      FRotator NewRotation = CurrentRotation;
      NewRotation.Yaw = FMath::FixedTurn(CurrentRotation.Yaw, DesiredRotation.Yaw, (RotationRate * DeltaTime).Yaw);
      
      // Apply the rotation
      MoveUpdatedComponent( FVector::ZeroVector, NewRotation, 0, true );
    

This is just a rough outline, but the current code does something like this in the PhysicsRotation() function of the CharacterMovementComponent when bOrientToMovement is true.

Ok ill try this thanks

So MoveUpdatedComponent is undefined dont know why please help so is RotationRate and CurrentRotation

Probably because this function was added in the upcoming build. Do like me : work on something else while waiting the new build. I’m sure you have plenty of other things to make/test. :wink:

Im trying to do this too in my game

Like I said, this is a rough outline :slight_smile: I’m at home and don’t have the exact code in front of me.

MoveUpdatedComponent was indeed a new function added. The basics of it are to call UpdatedComponent->MoveComponent(), so you could just do that instead.

RotationRate I believe is in CharacterMovementComponent (UMovementComp_Character in your build), but might be named slightly differently. Feel free to plug in your own rotation rate instead.

CurrentRotation is just an example, you’d probably want UpdatedComponent->GetComponentRotation(), or PawnOwner->GetActorRotation().

So i write this in which function which class?

“the current code does something like this in the PhysicsRotation() function of the CharacterMovementComponent” (actually UMovementComp_Character in your build)

I tried that with UseControllerRotationYaw to false but all i get is my character still strafing an dnot facing the direction

I have an idea that I think may work but I need to know how we use Normal() and RInterpTo() in ue4?

Acceleration.SafeNormal() is equivalent to the old Normal(NewAccel) you saw in the uscript example.

FMath::FixedTurn() is linear interpolation for rotators, similar to RInterpTo().

Is it possible physicsRotation is called in another function

It’s called by PerformMovement in the Character movement component, which is part of the update every frame. I was suggesting overriding it, as that’s where the current code performs the code for bOrientToMovement.