- Home /
Setting Max Angular Force For Y For Jumping
As in my code I set my max force for left and right as 40, but when i set it to 600 for my jump, i can move unrelistically fast. Any way i can just set the max y instead of x an z?
What about adding constant force and manipulating that when needed?
Answer by aldonaletto · Apr 30, 2012 at 04:40 AM
I don't know how you're using these max values - you should have posted your script.
Anyway, a good way to jump is to set the Y velocity directly - like this:
var jumpSpeed: float = 8.0;
function Update(){ ... if (Input.GetButtonDown("Jump")){ rigidbody.velocity.y = jumpSpeed; } } This code has a problem: you can jump even while in the middle of another jump. To avoid this, you can set a flag when starting a jump, and reset it when landing on the ground - but the ground or other objects where the rigidbody can land must have the same tag - Ground, for instance:
var jumpSpeed: float = 8.0; private var jumping = false; // flag jumping
function Update(){ ... if (!jumping && Input.GetButtonDown("Jump")){ rigidbody.velocity.y = jumpSpeed; jumping = true; } }
function OnCollisionEnter(col: Collision){ if (col.gameObject.tag == "Ground"){ jumping = false; // reset the flag when landing on some Ground object } }
Answer by Seth-Bergman · Apr 30, 2012 at 04:47 AM
need the script, not quite sure what you mean.. If you're using a character controller, you can use something like this:
http://unity3d.com/support/documentation/ScriptReference/CharacterController.Move.html
similar to above, one note: uses controller.isGrounded to automatically check for being grounded
not sure if your issue is one of move speed, or rotation. post the script if you could
I do not recomend using tag, but CompareTag as tag will malfunction.