Changing the projectile's angle
by KaiserImpact · in Torque 2D Beginner · 01/31/2014 (4:56 am) · 2 replies
Hello all to torque2d community.
i'm facing a problem on switching the projectile's angle to fire at a different direction.
i've been using the moveTo function to fire one of my projectile to a worldpoint as a test and it works fine. But now i am working on firing 3 projectiles in a cone shape such as the middle projectile tracks the player's position(already completed), and the other 2 projectiles firing at a different angle like those spaceship in raiden game.
To those who had never play before raiden game, basically this is what i want.
[IMG]http://imagizer.imageshack.us/v2/xq90/268/z01a.png[/IMG]
Circles are the projectiles
Star is the target
Arrows are the firing directions.
Many thanks in advance!
i'm facing a problem on switching the projectile's angle to fire at a different direction.
i've been using the moveTo function to fire one of my projectile to a worldpoint as a test and it works fine. But now i am working on firing 3 projectiles in a cone shape such as the middle projectile tracks the player's position(already completed), and the other 2 projectiles firing at a different angle like those spaceship in raiden game.
To those who had never play before raiden game, basically this is what i want.
[IMG]http://imagizer.imageshack.us/v2/xq90/268/z01a.png[/IMG]
Circles are the projectiles
Star is the target
Arrows are the firing directions.
Many thanks in advance!
About the author
#2
02/07/2014 (3:51 am)
Oh cool. didnt knew that i can have the seting linearVelocityPolar. Thanks mike! and thread closed
Associate Mike Lilligreen
Retired T2Der
function ShootsBehavior::fire(%this, %val) { if (%this.owner.isDead == true) return; if (%val == 0) { cancel(%this.fireSchedule); return; } if (!isObject(%this.object)) return; %projectile = %this.object.clone(); %projectile.setPosition(%this.owner.position); %projectile.setAngle(%this.owner.angle); %angle = %this.owner.angle + 90; %projectile.setLinearVelocityPolar(%angle, %this.projectileSpeed); %this.scene.add(%projectile); if (!isEventPending(%this.fireSchedule)) %this.fireSchedule = %this.schedule(%this.fireRate * 1000, "fire", 1); }Instead of MoveTo, I use setLinearVelocityPolar and by adjusting the angle for each of your projectiles, you can achieve the cone shape firing.