Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: HeathClose on August 08, 2017, 03:22:23 PM

Title: 2d Rotating Turret Bullet Direction [SOLVED]
Post by: HeathClose on August 08, 2017, 03:22:23 PM
I have this very simple 2d rotating turret.

(https://www.dropbox.com/s/6m477e8clp8g546/Screenshot%202017-08-08%2014.15.50.png?dl=1)

I has a look at 2d action on it so it tracks the player.

I have the bullets in Poolboss, and when the turret is tracking the player, it has coregamekit spawn action to spawn the bullets.

I'm having trouble figuring out how to get the bullet to fire in the direction of the player.  I've tried set velocity 2d.  I've tried add force 2d.  I've tried add relative force 2d.  Nothing seems to work on moving the bullet in the direction the barrel of the turret is facing when it fires.
Title: Re: 2d Rotating Turret Bullet Direction
Post by: djaydino on August 08, 2017, 09:45:36 PM
Hi,
It can be several things.
is the bullet moving at all?

Is the object select?

Do you have a (empty object) spawn point on the barrel to set the postion and rotation when a bullet is spawned.

Try using breakpoints to see where it goes wrong (right click on a state and select 'Toggle Breakpoint')

Maybe some settings on the rigidbody (kinematic, constrains,drag )
Title: Re: 2d Rotating Turret Bullet Direction
Post by: jeanfabre on August 09, 2017, 04:03:08 AM
Hi,

 you need to use the action "GetDirection", you get the direction of the turret, you then normalize that direction using (Vector3Normalize) to get a unit vector of that direction, multiply it by a speed coef use "Vector3Multiply" and set the velocity of your bullet using "SetVelocity" to this value you got with the above as soon as you spawned your bullet.

 Bye,

 Jean
Title: Re: 2d Rotating Turret Bullet Direction
Post by: HeathClose on August 09, 2017, 10:52:24 AM
The only get direction i see is a ugui action.  I don't see get direction on the ecosystem either.
Title: Re: 2d Rotating Turret Bullet Direction
Post by: HeathClose on August 09, 2017, 11:07:42 AM
Actually... I got this working with the following fsm on the bullet

I tried many variations of this yesterday, trying to get angles and whatnot... but it never dawned on me to just have the bullet look at the player and take off.  The relative action makes this work.

(https://www.dropbox.com/s/t1aw57pkj1zqefw/Screenshot%202017-08-09%2010.05.18.png?dl=1)
Title: Re: 2d Rotating Turret Bullet Direction [SOLVED]
Post by: jeanfabre on August 10, 2017, 03:01:54 AM
Hi,

 sorry, it was "transformDirection" and it's a action already with PlayMaker :)

 Bye,

 Jean