# Enlightenment about MovementComponent?

**URL:** <https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 11, 2014, 2:09am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298 "2014-03-11T02:09:37Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:09am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/21 "2014-03-11T02:09:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:09am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/22 "2014-03-11T02:09:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:09am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/23 "2014-03-11T02:09:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:09am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/24 "2014-03-11T02:09:59Z")

</div>

This part here what function was it in

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:09am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/25 "2014-03-11T02:09:59Z")

</div>

An override of the PlayerMove function inside the PlayerController State.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/26 "2014-03-11T02:10:00Z")

</div>

Ok wait i got an idea

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/27 "2014-03-11T02:10:00Z")

</div>

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:

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/28 "2014-03-11T02:10:01Z")

</div>

Ok ill try this thanks

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/29 "2014-03-11T02:10:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/30 "2014-03-11T02:10:01Z")

</div>

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. 😉

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/31 "2014-03-11T02:10:02Z")

</div>

Im trying to do this too in my game

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/32 "2014-03-11T02:10:03Z")

</div>

Like I said, this is a rough outline 🙂 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().

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/33 "2014-03-11T02:10:03Z")

</div>

So i write this in which function which class?

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/34 "2014-03-11T02:10:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/35 "2014-03-11T02:10:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/36 "2014-03-11T02:10:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/37 "2014-03-11T02:10:05Z")

</div>

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().

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/38 "2014-03-11T02:10:05Z")

</div>

Is it possible physicsRotation is called in another function

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/39 "2014-03-11T02:10:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 11:10am UTC](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298/40 "2014-03-11T11:10:10Z")

</div>

PlayerController by default has 2 states ‘moving’ and ‘spectating’. StartMoving just puts you into the ‘moving’ state. PlayerMove has actually gone from PC in the latest beta. All of the actual logic concerning _how_ the pawn moves is now in the pawn or movementcomponent class you are using. This should make it _much_ easier to make different games than it was in UE3, but still be able to build on our core walking Character class if that is what you need.

We do have plans to make it much easier to add additional states to the CharacterMovementComponent - using a name rather than an enum. We are _certainly_ going to give out all the source (for reference) for classes like PlayerController, Pawn and CharacterMovementComponent. Hopefully in the next beta.

If you can give us some more details on what you are trying to achieve, we maybe be able to improve this process further.

[Previous page](https://forums.unrealengine.com/t/enlightenment-about-movementcomponent/275298.md?page=1)
