- Home /
Unable to Apply External Forces to my Rigidbody
When using rigidbody.AddExplosionForce(), my player only goes up, He isnt effected on the X or Z axis, I believe its because of the way the players velocity is handled, or its the ForceMode (Impulse), If i use ForceMode.Force (The explosion works when its ForceMode.Force), It feels terrible and its just not as good as the instant velocity changes with the Impulse ForceMode, Here is my code:
void Movement() {
// Calculate how fast we should be moving
Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
targetVelocity = transform.TransformDirection(targetVelocity);
targetVelocity *= speed;
// Apply a force that attempts to reach our target velocity
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);
// Apply Gravity
rb.AddForce(new Vector3(0, -gravity * rb.mass, 0));
}
Anyway, I have no clue how to get around this, Because i need to use AddExplosionForce as it is a big mechanic in my game. And yes, Im using ExplosionForce correctly, It was working before I changed my movement script, Because my old movement script was unreliable and generally bad.
Thank you for your time :)
Your answer
Follow this Question
Related Questions
Rigidbody enemy Forcemode.VelocityChange 1 Answer
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Velocity of multiple rigidbody obiects in array 4 Answers
Question about rigidbody velocity 1 Answer
Rigidbody velocity has got different direction than VelocityChange force vector 1 Answer