- Home /
Why will this boolean not go back to false?
While I am not touching anything, the boolean should equal false. It' equals true as soon as I land on the ground at spawn, I jump, but it doesn't go back to false. Anyone know?
var walkAcceleration : float = 24; var cameraObject : GameObject; var maxWalkSpeed : float = 24; @HideInInspector var horizontalMovement : Vector2;
var jumpVelocity : float = 200; var grounded : boolean = false; var maxSlope : float = 60;
function Update () {
horizontalMovement = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
if(horizontalMovement.magnitude > maxWalkSpeed) {
horizontalMovement = horizontalMovement.Normalized; horizontalMovement *= maxWalkSpeed; }
rigidbody.velocity.x = horizontalMovement.x; rigidbody.velocity.z = horizontalMovement.y;
transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentyRotation, 0); rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") walkAcceleration, 0, Input.GetAxis("Vertical") walkAcceleration);
if(Input.GetButtonDown("Jump")&& grounded) rigidbody.AddForce(0, jumpVelocity, 0);
}
function OnCollisionStay (collision : Collision) { for(var contact : ContactPoint in collision.contacts) {
if(Vector3.Angle(contact.normal, Vector3.up) < maxSlope) grounded = true;
} }
Your answer
Follow this Question
Related Questions
Jump animation anticipation 2 Answers
Problem with jump bool. Help?! 0 Answers
touchCount to jump and create/destroy joints ios 0 Answers
mecanim boolean doesnt change -1 Answers
(C#) A better way to limit actions to once per button press? 2 Answers