- Home /
Question by
Rcocuzzo8 · Apr 23, 2016 at 08:53 PM ·
collision2d gametriggercollision detection2d-physics
2D collision not registering
Hi guys, I have tried just about EVERY solution I have found online and havent gotten any positive results on why it is that my 2D trigger-based collision is not working. ' Result of execution: turtle goes right through the gold piece without disabling it.
using UnityEngine;
alt text using System.Collections; public class playerScript : MonoBehaviour {
public Rigidbody2D rb;
public float speed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("Space key was pressed.");
rb.AddForce (new Vector3 (0, 300, 0));
} else if (Input.GetKey (KeyCode.RightArrow) && Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("Space key and Right Key.");
rb.AddForce (new Vector3 (10, 30, 0));
} else if (Input.GetKey (KeyCode.RightArrow)) {
Debug.Log ("Right key was pressed.");
rb.AddForce (new Vector3 (10, 0, 0));
} else if (Input.GetKey (KeyCode.LeftArrow)) {
Debug.Log ("Right key was pressed.");
rb.AddForce (new Vector3 (-10, 0, 0));
} else if (Input.GetKey (KeyCode.LeftArrow) && Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("Space key and Left Key.");
rb.AddForce (new Vector3 (-10, 30, 0));
}
}
void onTriggerEnter(Collider other) {
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
}
}
}
screen-shot-2016-04-23-at-42816-pm.png
(99.0 kB)
screen-shot-2016-04-23-at-42631-pm.png
(101.4 kB)
Comment
Answer by Soraphis · Apr 23, 2016 at 09:02 PM
have you tried removing the rigidbody from the gold coin (the component is not suggesting it for no reason, its kinda senseless)?
btw it is called "OnTriggerEnter" with capital "O" (which should solve your problem)
and why does everyone use "FixedUpdate" for no reason at all ...