Change Player Angle on Slope

I have some code which works off the PC in the PlayerWalking state and PlayerMove function that works out if the player is on a slope and adjusts their rotation/pitch.

One trace checks if the landscape is an upward slope and the other if its a downward slope. If theres a slope I adjust the rotation of the player e,g, Pawn.SetRotation(angledRotationDown);

It all works pretty well except I think because its running either 1 or sometimes 2 traces constantly I think this is impacting other stuff with the playerinput, I find some key press events are not triggering.

Has anyone got another suggestion as to how this could be done more efficiently? I was thinking through the anim tree but nothing lept out at me saying do it this way …

Cheers.

will MaxPitchLimit work for you?

I did some searches based on your suggestion and stumbled across a thread which looks like has a great solution UDK Forums Update - UDK Content Creation and Design - Epic Developer Community Forums. Will recode tomorrow, looks promising from what I want. Looks like I just needed some differnet keywords to rephrase my search.

I don’t think you need any traces at all.

So in your PlayerController you have access to your Pawn. Your Pawn has a “var vector Floor; // Normal of floor pawn is standing on (only used by PHYS_Spider and PHYS_Walking)” and you have the rotation of the Pawn from which you can get the forward vector.
Now all you really need is the dot product. Be aware that the following is relative to the Pawns Rotation. So you may be running uphill (backwards) but the slope is detected as being downhill because you are facing downhill! You can simply replace Pawn.Rotation with the Rotation you’re running in and that should give you an uphill/downhill slope result relative to that instead.

Something like this:


local vector PawnFloor;
local vector PawnForwardDirection;
local vector PawnForwardDirectionNoZ;
local float DotProduct;

PawnFloor = Pawn.Floor;
PawnForwardDirection = vector(Pawn.Rotation);
//remove Z and renormalize
PawnForwardDirectionNoZ = normal(PawnForwardDirection * vect(1, 1, 0);

DotProduct = PawnForwardDirectionNoZ dot PawnFloor;
if (DotProduct < 0.0f)
{
	//upward slope
}
else if (DotProduct > 0.0f)
{
	//downward slope
}
else //== 0.0f
{
	// no slope
}