I have an infinite world that allows players to switch from 3rd person control to an overhead RTS style mode for certain interactions (Terrain modifications in vehicles mostly - excavators, dump trucks, bulldozers, etc).
I’m trying to find a way to give the initial path when you make a vehicle move look a bit more realistic (reverse and turn if needed, or generate the path based on a max steer angle from the units initial rotation). Is something like this already implemented (I might be slightly blind, but couldn’t find too much), or will I need to write my own?
I have a general solution, lacking polish. But I like how it looks so far (in case others have a similar problem) - This is using Edy’s Vehicle Physics (I modified his code a bit and changed his function calls to my own, since I like capitols and underscores more - SendInput == SEND_INPUT more or less):
`
void FOLLOW_PATH ()
{
if( CURRENT_WAYPOINT >= PATH.vectorPath.Count )
{
CAR_CTRL.SEND_INPUT( 0.0f, 0.0f, 0.0f, 0.0f, false );
PATH = null;
return;
}
POINT = TRANSFORM.InverseTransformPoint( PATH.vectorPath[ CURRENT_WAYPOINT ] );
ANGLE = Vector3.Angle( ( PATH.vectorPath[ CURRENT_WAYPOINT ] - TRANSFORM.position ).normalized, TRANSFORM.forward );
if( POINT.z > 0.0f )
{
if( MOTOR == -1.0f && ANGLE > 45.0f )
{
MOTOR = -1.0f;
}
else
{
MOTOR = 1.0f;
}
}
else if( POINT.z < 0.0f )
{
MOTOR = -1.0f;
}
else
{
MOTOR = 0.0f;
}
if( POINT.x > 0.0f )
{
if( MOTOR > 0.0f )
{
TURN = Mathf.MoveTowards(TURN, 1.0f, Time.fixedDeltaTime * 5.0f);
}
else if( MOTOR < 0.0f )
{
TURN = Mathf.MoveTowards(TURN, -1.0f, Time.fixedDeltaTime * 5.0f);
}
else
{
TURN = Mathf.MoveTowards(TURN, 0.0f, Time.fixedDeltaTime * 5.0f);
}
}
else if( POINT.x < 0.0f )
{
if( MOTOR > 0.0f )
{
TURN = Mathf.MoveTowards( TURN, -1.0f, Time.fixedDeltaTime * 5.0f );
}
else if( MOTOR < 0.0f )
{
TURN = Mathf.MoveTowards( TURN, 1.0f, Time.fixedDeltaTime * 5.0f );
}
else
{
TURN = Mathf.MoveTowards( TURN, 0.0f, Time.fixedDeltaTime * 5.0f );
}
}
else
{
TURN = Mathf.Lerp( TURN, 0.0f, Time.fixedDeltaTime * 5.0f );
}
CAR_CTRL.SEND_INPUT( TURN, Mathf.Clamp( MOTOR, 0.0f, 1.0f ), ( -1.0f * Mathf.Clamp( MOTOR, -1.0f, 0.0f ) ), 0.0f );
if( Vector3.Distance( TRANSFORM.position, PATH.vectorPath[ CURRENT_WAYPOINT ] ) < NEXT_WAYPOINT_DISTANCE )
{
CURRENT_WAYPOINT++; return;
}
}`