Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Rotate Bullet with rotating Turret PROPERLY

$
0
0
Hey all, I am making a top down 2D shooter. I want to achieve the following: ![alt text][1] A is the base of the turret that rotates around itself. B is the cannon where the blue bullets spawn and fire from. My problem is that I can't make the bullets rotate properly with the cannon. See picture B ![alt text][2] I am using PoolManager to instantiate the bullet. Everything works fine except for the bullet rotation. Here is my code: Turret.js var projectile : Transform; var cannon : Transform; private var spawnPosition : Vector3; function Start () { Fire(); } function Update() { transform.Rotate(0, 10 * Time.deltaTime, 0); // rotate turret } function Fire () { spawnPosition = cannon.position; var bullet : Transform = PoolManager.Pools["ProjectilePool"].Spawn(projectile, spawnPosition, projectile.rotation); Invoke("Fire", 2); // invoke function every 2 seconds } Bullet.js var speed : float = 10; function Update () { transform.Translate( Vector3(0,0,speed) * Time.deltaTime); } I know that I shouldn't be using projectile.rotation in the Turret.js script but I can't figure out what to use instead. When I use the cannon's rotation, the bullet fires in the wrong axis. Any help would be greatly appreciated! Thank you! [1]: /storage/temp/26361-turret.jpg [2]: /storage/temp/26362-picture-b.jpg

Viewing all articles
Browse latest Browse all 592

Trending Articles