- Home /
Question by
neurovics670 · Jun 07, 2018 at 05:42 PM ·
charactercontrollercharacter movementcharacters
Please how do i modify this code so that my character can only run in the forward direction and never backwards
void FixedUpdate()
{
Run ();
Jump ();
rBody.velocity = transform.TransformDirection (velocity);
}
void Run()
{
if (Mathf.Abs (forwardInput) > inputSetting.inputDelay)
{
//move
velocity.z = moveSetting.forwardVel * forwardInput;
}
else //zero.velocity
velocity.z = 0;
}
Comment
Answer by _samuel12345 · Jun 07, 2018 at 05:59 PM
Try this:
float playerZPos;
void Update(){
if(transform.position.z > playerZPos){
playerZPos = transform.position.z;
}
if(transform.position.z < playerZPos){
transform.position.z = playerZPos;
}
}
Your answer