- Home /
Question by
Momil_Ijaz · Jun 09, 2018 at 09:33 AM ·
unity 2drigidbody2dontriggerenter2d
OnTriggerEnter2D misbehaves when called quickly
I am trying to make a replica of knife hit in unity2d and I am having issue when i try to throw knives quickly at my log ,When i throw knives slowly they get stabbed in perfectly but when i throw them quickly :
1)My log experiences jerks (even though it's rigidbody2d has xy constraints active).
2)And some knives don'y get stabbed in to the point i want them to,means they are mostly out of log. As shown in the image below,green knife is ok but red circles ones are leaping out of log.
Here's my code on log to detect incoming knives.
void OnTriggerEnter2D(Collider2D col){
Vector3 WoodchipPos=new Vector3(col.transform.position.x,col.transform.position.y,-2f);
if (col.gameObject.tag == "Knife" && !gameover) {
col.attachedRigidbody.bodyType=RigidbodyType2D.Kinematic;
col.gameObject.transform.position = new Vector3 (0f,0.87f,-1f);
col.attachedRigidbody.velocity = Vector2.zero;
col.gameObject.tag = "StabKnife";
mylight.intensity = 3f;
Instantiate (WoodChips, WoodchipPos, WoodChips.transform.rotation);
col.transform.parent = this.transform;
}
}
Comment