playMaker

Author Topic: 2d Rotating Turret Bullet Direction [SOLVED]  (Read 167 times)

HeathClose

  • Full Member
  • ***
  • Posts: 223
    • View Profile
2d Rotating Turret Bullet Direction [SOLVED]
« on: August 08, 2017, 12:22:23 PM »
I have this very simple 2d rotating turret.



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.
« Last Edit: August 09, 2017, 08:15:11 AM by HeathClose »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2296
    • View Profile
    • jinxtergames
Re: 2d Rotating Turret Bullet Direction
« Reply #1 on: August 08, 2017, 06: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 )

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: 2d Rotating Turret Bullet Direction
« Reply #2 on: August 09, 2017, 01: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

HeathClose

  • Full Member
  • ***
  • Posts: 223
    • View Profile
Re: 2d Rotating Turret Bullet Direction
« Reply #3 on: August 09, 2017, 07:52:24 AM »
The only get direction i see is a ugui action.  I don't see get direction on the ecosystem either.

HeathClose

  • Full Member
  • ***
  • Posts: 223
    • View Profile
Re: 2d Rotating Turret Bullet Direction
« Reply #4 on: August 09, 2017, 08: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.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: 2d Rotating Turret Bullet Direction [SOLVED]
« Reply #5 on: August 10, 2017, 12:01:54 AM »
Hi,

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

 Bye,

 Jean