I’m experimenting with the Top Down template. I modified it a little bit to make a character walk around in the level, by using (Simple) Move To Location. How can I make the character turn when changing direction (at corners, or after changing the navigation goal). Currently the rotation is always instantly set to the goal. Thanks!
Ran into this myself in UDK 3 The following is a snippet from my PawnController for a 3rd person game I think It might address your issue. This is written In UnrealScript but I think the key is to set desired rotation, and lock desired rotation.
State Moving
{
begin:
`log("In Moving State");
Pawn.LockDesiredRotation(False);
`log("Locked DesiredRotation");
Pawn.SetRotation(NewRotation);
`log("Set New Rotation");
Pawn.SetDesiredRotation(NewRotation);
`log("Set DeskredRotation");
Pawn.LockDesiredRotation(True, false);
`log("LockDesiredRotation");
MoveTo(Destination);
`log("Did MoveToDestination");
//Pawn.SetLocation(Destination);
AmIDoneMoving();
}
And heres a big fat IF function to run through what all the rotations are
function AmIDoneMoving()
{
`log(" IN AmIDoneMoving");
YChange = 0;
XChange = 0;
`log(" MoveArray.Length = "$MoveArray.Length);
//`log("In Am I done Moving: Array Index = " $ArrayIndex);
if(MoveArray.Length > 1)
{
`log("Removed last array entry");
MoveArray.Remove(MoveArray.length-1, 1);
Destination = MoveArray[MoveArray.length-1];
//Calculating pawn direction of travel
if(Destination.X > Pawn.location.X)
{
//`log("Dest.x > Pawn.X ");
XChange = Destination.X - Pawn.Location.X;
//`log("XChange " $XChange);
}
Else If( Destination.X < Pawn.location.X )
{
//`log("Dest.x < Pawn.X ");
XChange = Pawn.Location.X - Destination.X;
//`log("XChange " $XChange);
}
If(Destination.Y > Pawn.location.Y)
{
YChange = Destination.Y - Pawn.Location.Y;
}
Else If( Destination.Y < Pawn.location.Y )
{
YChange = Pawn.Location.Y - Destination.Y;
}
//Setting NewRotation for pawn to face
if(YChange > XChange)
{
//Moving Positive Y
if(Destination.Y > Pawn.Location.Y)
{
//`log("Facing Positive Y ");
NewRotation.Yaw = 90 * DegToUnrRot;
//`log("NewRotation " $NewRotation);
}
//Moving Negative Y
Else If (Destination.Y < Pawn.Location.Y)
{
//`log("Facing Negative Y ");
NewRotation.Yaw = 270 * DegToUnrRot;
//`log("NewRotation " $NewRotation);
}
}
// If moving on X axis
Else if(XChange > YChange)
{
//Moving Positive X
if(Destination.X > Pawn.Location.X)
{
//`log("Facing Positive X ");
NewRotation.Yaw = 0;
//`log("NewRotation " $NewRotation);
}
//Moving Negative X
Else If (Destination.X < Pawn.Location.X)
{
//`log("Facing Negative X ");
NewRotation.Yaw = 180 * DegToUnrRot;
//`log("NewRotation " $NewRotation);
}
}
Heres a link to a video with my iteration frustrations with this part.