Question by
johntk · Apr 26, 2016 at 06:46 AM ·
collisioncolliderfirst person controller
OnCollisionEnter causing first person controller to go haywire
Dia dhuit,
I have created a first person controller as an enemy in my game (Zombie), my character is an Archer.
I have a script to parent the fired arrow to the collided object which works fine for most objects in the game, but my enemy object (Zombie) speeds up and moves all around the place on a collision, I'm new to unity, I've spent a few hours trying to resolve this with out success.
The method I think is causing the problem:
void OnCollisionEnter(Collision collision){
if (this.flying) {
this.flying = false;
Destroy (this.GetComponent<Rigidbody>());
// this.transform.position = collision.transform.InverseTransformPoint(collision.contacts[0].point);
this.transform.position = collision.contacts [0].point;
GameObject anchor = new GameObject ("ARROW_ANCHOR");
anchor.transform.position = this.transform.position;
anchor.transform.rotation = this.transform.rotation;
anchor.transform.parent = collision.transform;
this.anchor = anchor.transform;
collision.gameObject.SendMessage ("arrowHit", SendMessageOptions.DontRequireReceiver);
}
}
I think the issue is with the line anchor.transform.parent = collision.transform;
Maybe there is a solution without parenting the arrow to the Zombie?
I'm stumped at this stage any help appreciated.
Comment