- Home /
How to rotate an Instantiated object?
Hello i need help rotating lasers becuase when my player rotates, the laser does not face the direction the player is shooting. Here's some of my script right now -
' var ourRotation : int = transform.rotation.y;
if(Input.GetButtonDown("Jump")) {
//create our laser
var laser0 = Instantiate(laserPrefab, transform.Find("spawn").transform.position,Quaternion.identity);
//add force to our laser
laser0.rigidbody.AddForce( transform.forward * force);
//rotate our laser
laser0.Rotate(0, ourRotation, 0);
}`
Answer by Max Kaufmann · Dec 13, 2010 at 03:20 AM
laser0.rigidbody.MoveRotation(transform.Find("spawn").rotation);
Aside: be aware that we're doing a lot of dynamic lookups (in this case three):
.rigidbody
transform
Find()
If this is inner-loop code, you'll want to save those references.
Your answer
Follow this Question
Related Questions
How to rotate an instantiated object by a fixed amount before it is spawned 2 Answers
Upon being instantiated, why is my object moving upwards ? 2 Answers
Android based ARCore example ObjectManipulation using Joystick Controller 0 Answers
Instantiated object rotation abruptly. 0 Answers
Instantiate question 1 Answer