- Home /
Adjusting rotation on instatiated object clone
Need some help here. Have instantiated a laser beam for my space shooter and sent it flying off into space. The trouble is, it's not horizontal, but vertical. I've tried to adjust the rotation, but nothing seems to work. Is there a trick to it? Thanks!
What do you mean by "I've tried to adjust the rotation"? What have you tried? Please post your code. Generally, it's sufficient to set the transform.eulerAngles immediately after instantiating, or directly passing the right Quaternion as a parameter to the Instantiate function.
public void FireLaser()
{
if(currentBatteryPower>0)
{
//Debug.Log("What is the value?" + Battery.value);
Debug.Log(maxBatteryPower);
Rigidbody laserClone;
laserClone = Instantiate(laserBolt, cam.position, cam.rotation)as Rigidbody;
// Set velocity to be the direction of the player camera (transform)
laserClone.velocity = transform.TransformDirection(new Vector3(0,0,speed));
// Turn off collisions with the player
//laserBolt.GetComponent<Collider>(laserBolt.collider, transform.root.collider);
soundSource.PlayOneShot(Laserbolt, 1f);
currentBatteryPower-=powerCost;
Battery.value=currentBatteryPower/maxBatteryPower;
}
Answer by 334499p · Jul 20, 2015 at 06:32 PM
GameObject projectile = (GameObject)Instantiate(laserPrefab, shootSpot.position, shootSpot.rotation);
projectile.transform.Rotate( myVector3Rot);
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
I made a script that shoots but the bullet's rotation is wrong when instantiated? 2 Answers
Instantiated objects always facing the center 2 Answers
Rotate an Instantiated GameObject a set amount from another instantiated GameObject? 1 Answer
Distribute terrain in zones 3 Answers