- Home /
Need help with scripting bug fix. pleease
hey guys, so I have set up an alpha version of my WIP game to let my friends test it for bugs. They found out that there is something wrong with my collision script. When they move the character to another collider (e.g. fence) and press the button multiple times fast in a row, the character is starting to run again. against the fence but you cannot move it anymore. I hope you guys can help me. I post the link to my game as well as the code. Game: http://nubz.parseapp.com/
charMovement script: void FixedUpdate () { if (Input.GetKeyDown (KeyCode.LeftArrow) && rigidbody.isKinematic == true){ rigidbody.isKinematic = false; rigidbody.velocity = new Vector3(0, 0, speed); transform.rotation = Quaternion.LookRotation(rigidbody.velocity); anim.speed = animSpeed; anim.SetFloat("Speed", animSpeed); } if (Input.GetKeyDown (KeyCode.RightArrow) && rigidbody.isKinematic == true){ rigidbody.isKinematic = false; rigidbody.velocity = new Vector3(0, 0, -speed); transform.rotation = Quaternion.LookRotation(rigidbody.velocity); anim.speed = animSpeed; anim.SetFloat("Speed", animSpeed); } if (Input.GetKeyDown (KeyCode.UpArrow) && rigidbody.isKinematic == true){ rigidbody.isKinematic = false; rigidbody.velocity = new Vector3(speed, 0, 0); transform.rotation = Quaternion.LookRotation(rigidbody.velocity); anim.speed = animSpeed; anim.SetFloat("Speed", animSpeed); } if (Input.GetKeyDown (KeyCode.DownArrow) && rigidbody.isKinematic == true){ rigidbody.isKinematic = false; rigidbody.velocity = new Vector3(-speed, 0, 0); transform.rotation = Quaternion.LookRotation(rigidbody.velocity); anim.speed = animSpeed; anim.SetFloat("Speed", animSpeed); } }
collision script that is attached to every object at the field: private Animator anim;
void OnCollisionEnter ( Collision collision) {
if (collision.gameObject.CompareTag ("Player")) {
anim = collision.gameObject.GetComponent<Animator>();
anim.SetFloat("Speed", 0);
collision.rigidbody.isKinematic = true;
}
}
void OnCollisionExit ( Collision collision) {
collision.rigidbody.isKinematic = true;
}
I would check the "kinematic change" via Debug.Log(collision.rigidbody.is$$anonymous$$inematic);
Your answer
Follow this Question
Related Questions
OnCollisionEnter not being called, between a Rigidbody and a Box Collider 1 Answer
Why are my projectiles facing the wrong way? 1 Answer
Detect collision/trigger between two body without rigidbody? 3 Answers
Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer