Hi!
I’ve been trying to attach a clone projectile to the gameobject it hits, but I can’t seem to get it right…
Anyone got any tips?
Hi, welcome to the forum!
Can you describe what you have tried so far?
Yeh sure!
I tried like:
transform = collision.parent - and stuff like that.
But that didn’t work, I think I have to get the name of the gameobject it collide with some how.
I found the Script Reference for parent, Unity - Scripting API: Transform.parent, and tried to change it to work the way I wanted it, but I’m not sure if I did it right, or if it’s just that you can’t use the Collision to name the other object.
This is my code so far, it’s not working because I get some error messages, but I hope you see what I’m trying to do…
function OnCollisionEnter (collision : Collision) {
// stop the arrow
rigidbody.useGravity = false;
rigidbody.Sleep();
rigidbody.drag = 10000;
rotation = false;
rigidbody.freezeRotation = true;
var CollObject = Collision.gameObject;
this.parent = CollObject;
}
Ok, so I think I know what I have to do…
I have to make the target instantiate a clone of the arrow that hits, and destroy the original arrow…
So, I’m wondering, what have I done wrong here?
Or in other words, what should I do to make it work?
var arrow : Rigidbody;
var arrowClone : Rigidbody;
function OnCollisionEnter (collision : Rigidbody) {
if (collision==arrow) {
var clone = Instantiate(arrowClone,arrow.transform.position,arrow.transform.rotation);
clone.parent = transform;
}
}
Which object is this script attached to? I imagine it would have to be attached to the arrow to get the clone in the right place, but you refer to the arrow with a variable as if it were another object.
I tried attaching the script to the target, because it seems like I need to to make the arrow a child of the target, so that it moves with it!
Like, if the target tiped over after the arrow hit, it will look weird if the arrow stays in mid-air!