collision problems
Basically i have a game with moving objects that if touches my player, player dies. in my death script i have :
// Die by collision void OnCollisionEnter2D(Collision2D other) { Die(); }
and i added a rigidbody and a box collider to my player and a box collider to my moving objects. My problem is that when my player collides with the moving object my player would either tilt to the sides, shake or my moving object will tilt (the player tends to tilt the most). I tried freezing the rotation and position on the rigidbody- constraints. But it didn't work. How to i stop this from happening? can someone please help me. Thank you. Here's my death script:
using UnityEngine;
public class death : MonoBehaviour
{
// The force which is added when the player jumps
// This can be changed in the Inspector window
public Vector2 jumpForce = new Vector2(0, 300);
// Update is called once per frame
void Update ()
{
// Jump
if (Input.GetKeyUp("space"))
{
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
GetComponent<Rigidbody2D>().AddForce(jumpForce);
}
}
// Die by collision
void OnCollisionEnter2D(Collision2D other)
{
Die();
}
void Die()
{
Application.LoadLevel(Application.loadedLevel);
}
}
Are you saying that Die() is not being called? Does Die() run on collision or is it running but you also have this side effect?
Your answer
Follow this Question
Related Questions
OnTriggerEnter 2 Answers
unity2d One Scene Not Working 0 Answers
StartCoroutine in Collision unwork 1 Answer
Tilemap collider 2D not working 2 Answers