Collision causing FPC to go haywire
Dia dhuit,
I have created a first person controller as an enemy in my game (Zombie), my character is an Archer using Arrows as projectiles fired using:
if(Input.GetButton("Fire1")) {
shotForce += 45f;
}
if (Input.GetMouseButtonUp(0)) {
Rigidbody shot = Instantiate (projectile, shotPos.position, shotPos.rotation) as Rigidbody;
shot.mass = shotMass;
shot.AddForce (Camera.main.transform.forward * shotForce);
shotForce = 0f;
}
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.
I have a Rigidbody, Charcter controller and First person controller on the Zombie.
I have a Rigidbody and Sphere Collider on the Arrow.
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.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.
Your answer
Follow this Question
Related Questions
OnCollisionEnter causing first person controller to go haywire 0 Answers
How to move an object on a terrain that will always stay on top of the terrain? 2 Answers
My health potion worked and now it doesn't. 1 Answer
GameObject not destroying on Collision 1 Answer
Restrict held object movement 0 Answers