Question by
DeadCatInABag · Aug 23, 2019 at 01:56 PM ·
movementjumpingplatformercontroller
need help with in-air movement
Basically, Im trying to implement a full force based movement controller, but i cant figure out how to control the player in the air without either cancelling all current momentum, or allowing the player to speed up to much midair. Here is my current code, if anyone has any ideas how to fix this it could be much appreciated.
if (ifGrounded())
{
Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
targetVelocity = slopedMovementController.transform.TransformDirection(targetVelocity);
targetVelocity *= speed;
Vector3 velocity = rb.velocity;
Vector3 velocityChange = (targetVelocity - velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
rb.AddForce(velocityChange, ForceMode.VelocityChange);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612211102im_/https://answers.unity.com/themes/thub/images/avi.jpg)