- Home /
Why is my 2D Collision Delaying or Missing?
Hello,
I'm trying to get my boulder to flip upwards whenever the player hits the button down and the item to throw is within the throwing area. It feels like there is a throw delay, because I've got no delay for hitting the fire button to throw, so I'm hammering away and the item is still missed. The toss field is a Box Collider 2D with the trigger field checked and the boulder is a polygon collider with a 2D rigidbody. My code is below the picture. I untag the boulder so if it hits the character after it was tossed nothing happens.
using UnityEngine;
using System.Collections;
public class Tosser : MonoBehaviour {
public GameObject ScoreCounter;
void OnTriggerStay2D(Collider2D other){
if (other.gameObject.tag == "Boulder" && Input.GetButtonDown("Fire1"))
{
other.rigidbody2D.velocity = new Vector2(-20f,50f);
ScoreCounter.SendMessage("AddPoint");
other.gameObject.tag = "Untagged";
}
}
void OnTriggerEnter2D(Collider2D other){
if (other.gameObject.tag == "Boulder" && Input.GetButtonDown("Fire1"))
{
other.rigidbody2D.velocity = new Vector2(-20f,50f);
ScoreCounter.SendMessage("AddPoint");
other.gameObject.tag = "Untagged";
}
}
}
Any help would be greatly appreciated, thanks!
Your answer
Follow this Question
Related Questions
Unexpected behaviour of OnTriggerStay2D 0 Answers
Boxcollider2D, Trigger not working 2 Answers
BoxCollider2D, Trigger not working 1 Answer
2D box collision not working,2d Box Collider not working 0 Answers