Question by
Azumikkel · May 13, 2021 at 07:29 PM ·
vector3velocityvector2rigidbody.addforcerigidbody.velocity
Speed limit to AddForce (without limiting velocity of rigidbody)
Hi, I'm trying to control my character's movement speed through rigidbody. I want to be able to add force in the direction of player movement input, but to not add any force that exceeds a max walking speed. I want the character to be able to move faster than the max walking speed if affected by other physics forces though
float maxSpeed = 10f;
FixedUpdate() {
Vector3 addedVelocity = new Vector3(walkDir.x, 0, walkDir.y);
addedVelocity = transform.TransformDirection(targetVelocity);
addedVelocity *= speed;
rigidBody.AddForce(addedVelocity, ForceMode.VelocityChange);
}
How do I modify this so that Addforce won't add any more force than necessary to reach max speed? (but won't slow down player if they go faster by other means)
Comment
Your answer
Follow this Question
Related Questions
Only limit player input and not external forces (Rigidbody 3D) 1 Answer
Bullet shooting not working 0 Answers
RigidBody Controller Forces 0 Answers
A line between two objects with conditions 0 Answers
My bullets don't fire properly 0 Answers