- Home /
Getting Turret to Fire on the Correct Top-Down Plane
So I developed my own bullet-hell script for creating enemies that can fire in multiple patterns. While there are many kinks I need to work out, it works fine. The problem is that due to how i'm changing my game, I am transitioning from 2D to 3D. As such. I would like my bullet hell emitter, which currently fires on the xy plane to fire on the xz plane. Given that I am terrible at vector math, I would like some help with this. Here is the relevant code.
Rigidbody2D Shot;
float angle = (rotateOffset + emitterDir[i] + Random.Range (-firingArc,firingArc)) * Mathf.Deg2Rad;
Shot = Instantiate (ProjectileTest, target.position, Quaternion.Euler ((new Vector3(Mathf.Sin((angle * Mathf.Rad2Deg)),0,Mathf.Cos((angle * Mathf.Rad2Deg)))))) as Rigidbody2D;
Shot.velocity = transform.TransformDirection ((new Vector3(Mathf.Sin(angle),0,Mathf.Cos(angle))) * bulletspeed);
You will also notice that the shots are being instantiated as Rigidbody2Ds. This is the only way they currently work, because for some reason whenever I try to instantiate Rigidbodys, they don't move.
Any help would be greatly appreciated.
Your answer
Follow this Question
Related Questions
Change velocity direction 1 Answer
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Rigid Body relative speed 1 Answer
How can I convert velocity/direction to Force? 3 Answers
*= Mathf.Min 1 Answer