Hi All,
How do I script the rotation of an object?
I have a simple game where the player controls a ship. You shoot pressing the space bar. Everything is working great except the power up. When the player moves over a pink balls (representing a stand in for the power up) He is able to fire 2-5 more additional lasers. The first player bullet instantiates where expected to. (In the front center of the ship) The additional lasers are supposed to instantiate to the left or right of the player’s default weapon. Instead they appear to come out of the back of the ship. Upon investigation, it seems like the players model’s transform is reversed. The “Front” of the ship is actually facing the tail. I tried to reverse this but to no avail.
I then tried to fix the error with script. The idea was that I can just change the rotation of the power up bullets upon instantion. Despite my efforts, it STILL appears to come out of the ship’s rear. How do I code the proper behavior of all bullets coming out of the front of the player’s ship? Thanks in advance.
Code:
if (Input.GetKeyDown("space"))
{
//creates the missle
if ( bullettype == 0 ){
var newbullet : GameObject = Instantiate (bulletprefab, transform.position, transform.rotation);
}
else if (bullettype == 1 ){
Instantiate (bulletprefab, tranform.position, Quaternion.Euler (Vector3(0, -20,0) ) );
Instantiate (bulletprefab, transform.position, transform.rotation );
Instantiate (bulletprefab, transform.position , Quaternion.Euler(Vector3(-180, 20,0) ) );
}
else if (bullettype == 2 ){
Instantiate (bulletprefab, transform.position, Quaternion.Euler (Vector3(0, -20,0) ) );
Instantiate (bulletprefab, transform.position, transform.rotation);
Instantiate (bulletprefab, transform.position, Quaternion.Euler (Vector3(90, 20,0) ) );
Instantiate (bulletprefab, transform.position, Quaternion.Euler (Vector3(90, -40,0) ) );
Instantiate (bulletprefab, transform.position, Quaternion.Euler (Vector3(90, 40,0) ) );
}
}
}
Here’s a picture of what the desired direction should be.
http://www.flickr.com/photos/36249344@N07/5211616385/lightbox/