I have a ship and I want it to fire a laser, I believe that all I need help with is when it’s first instantiated, it’s always facing forward on the z axis, I need it to be facing the same direction as the ship or the spawnpoint, as the spawnpoint is attached to the ship so that it shoots in the direction the ship is facing. I’m not looking for someone to write me a full script, I’m really just looking for the right word to look up in the scripting reference, or even a English-based example. If there happens to be a CopyRotaion command that would be awesome, but it doesn’t ever seam to be that simple
if the script that fires the laser is on the ship, you could use something like:
instantiated lasers rotation = this.transform.forward (where this.transform.forward is the forward vector of the current game object the script is attached to)
Instantiate() takes a quaternion as its third argument; for this argument, simply submit the rotation of the object that’s doing the instantiating (e.g. the ship or spawnpoint).
Wow, I feel dumb, I cant believe I couldn’t figure that out >.<
I’m on to my next little difficulty now, if anyone wants to throw me a bone with this one. I cant seam to get the laser to shoot in the deirection of the ship now. I’ve tried using
laser.Rigidbody.AddForce(transform.forward * 1000);
transform.Translate(0,0,1);
each one of those I used separately of course. transform.Translate seamed to get me the closest to my goal. it shot the laser in the right direction as far as the ships y rotation, but when I fly up or down the laser would still shoot perfectly horizontal, doe’s that make sense? How to do I get this laser to shoot in the proper direction?
Alright I got it! Not sure why, but I used the transform.Translate on the laser itself and it worked that time. Thanks for your help with the rotation everyone.
Strange. Rigidbody.AddForce should work, there’s something weird going on. If your laser beam’s collider is being instantiated overlapping another collider it might cause some freaky behaviour. If that’s the case, you want to use Physics.IgnoreCollision or offset it’s position slightly.