Hey all,
I am making a top down 2D shooter. I want to achieve the following:
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
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!