Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: FrankDePaul on February 09, 2018, 09:42:59 PM

Title: 2d Turret firing.
Post by: FrankDePaul on February 09, 2018, 09:42:59 PM
I have looked through the forums and still cant get this to work. I have turrets that rotate on the Z axis. There are a lot of them. I have them rotating to track enemies. The issue I am running into is bullet firing.

I can spawn bullets, but unsure of what functions to use to have them travel in the direction the turret is facing. I can affect the rotation of the bullet object graphic, but not the direction it flies.
Title: Re: 2d Turret firing.
Post by: Captaincrud on February 10, 2018, 03:02:03 AM
you could ray cast to there end distance location or you could get the facing of the turrent then move bullet in that direction each frame.
Title: Re: 2d Turret firing.
Post by: FrankDePaul on February 10, 2018, 10:03:25 AM
How would I go about getting the facing of the turret. I can't seem to find an action for that. I am a bit of a beginner to playmaker. I can see how to do it in 3d, but 2d on the Z axis seems a bit more complicated.

Thanks!
Title: Re: 2d Turret firing.
Post by: FrankDePaul on February 10, 2018, 11:56:26 AM
To add to this, does anyone know of a Raycast tutorial using fast bullets. I can fire shots in the correct direction now, but they lag behind. I can speed the bullet up a bit and offset the turret rotation, but I think raycasting might be a better idea.
Title: Re: 2d Turret firing.
Post by: antibob on February 10, 2018, 09:49:17 PM

I have a 2D shooter project in the works and used a couple of different solutions.

One is to get the speed or velocity of the turret and add it to the bullet along with the speed, velocity or force of the bullet. You can use the Add Relative Force action.

To get the direction of a Vector2D I use a "projectile spawn" empty game object as a child of a the "turret". The spawn is offset in the forward position infant of the turret and set as a child of turret. Subtract the Projectile_Spawn from the Turret_Position to get your direction. Add a multiplier to the result and use it for 2D Add Force and you should be in business.

Here is screenshot.

Title: Re: 2d Turret firing.
Post by: FrankDePaul on February 11, 2018, 12:59:11 AM
Thanks! Got it working