Question by
cgKiwi · Mar 24, 2016 at 09:39 PM ·
rotationinstantiatetransformrigidbody2dclone
Instantiated object does not inherit rotation.
So I am trying to shoot a bullet in relation to my characters rotation, but I am stuck. The bullet will always go in the forward direction.
Here is my code.
var Bullet : Rigidbody2D;
var BulletSpawn : Transform;
function shoot(){
var clone : Rigidbody2D;
clone = Instantiate(Bullet,BulletSpawn.transform.position,BulletSpawn.transform.rotation) as Rigidbody2D;
clone.velocity = clone.transform.TransformDirection(Vector3(0,BulletSpeed));
}
Thanks.
Comment
Answer by seth_slax · Mar 25, 2016 at 03:08 AM
Assign your character's rotation to the bullet in the Instantiate method.