playMaker

Author Topic: Shooting projectiles in the direction the players facing[SOLVED]  (Read 4166 times)

lacju

  • Playmaker Newbie
  • *
  • Posts: 3
Shooting projectiles in the direction the players facing[SOLVED]
« on: February 08, 2017, 02:18:34 AM »
Hello,

I've been trying to figure out how to get projectiles to move in the direction the player is facing. I've spent hours upon hours googling, trying suggestions to problems similar to mine as well as trial and error but I'm getting nowhere.

I was able to achieve this behavior very easily before I started using Playmaker via my own script but I'd really like to learn a solution to this using Playmaker as it seems like a very useful concept I know I'll need later.

Here is a video of what currently happens in my game when I fire. I'd like the projectiles instead to be oriented in and move in the direction the player is facing (two different operations I'm sure but I'd really appreciate some guidance on how to do both).


Please turn your speakers down before viewing, for some reason the screen recorder I used produced a lot of loud staticy noise.

https://youtu.be/iqfqKnkrTwM
« Last Edit: February 15, 2017, 02:33:20 AM by jeanfabre »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Shooting projectiles in the direction the players facing
« Reply #1 on: February 08, 2017, 02:56:13 AM »
Hello, what are you using for firing projectiles?

Do you create them on key press and apply force, use translate or something else?

You can find a get forward direction here:

http://hutonggames.com/playmakerforum/index.php?topic=14246.0

In the moment of shot, get the forward direction of the ship and set it to the bullet.
Available for Playmaker work

lacju

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Shooting projectiles in the direction the players facing
« Reply #2 on: February 08, 2017, 06:52:05 PM »
The projectile firing/spawning is handled by a "Weapon" object that is a child of the "Ship" object. Here are the FSMs attached to the weapon object.

http://imgur.com/a/b4IWC







Thanks for that link, I will take a look at some of the actions.

antibob

  • Playmaker Newbie
  • *
  • Posts: 24
    • BillsClass
Re: Shooting projectiles in the direction the players facing
« Reply #3 on: February 08, 2017, 08:03:22 PM »
Are you using Physics to launch the projectile or Transform.Translate?

Just as Lacju mentioned, spawn a projectile at a spawn point (Empty Game Object) that is a child of the ship, then translate, addForce or setVelocity in the "forward" direction the projectile. Just be sure to use "self space" and not "world space" when translating or adding force to the projectile if using a "forward" direction.

Alternatively, you can use the "Transform Direction" of the ship and use it to direct the projectile based on a vector3. Set the "Location Direction" Y:1 (if Y is "forward direction").

-ab

lacju

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Shooting projectiles in the direction the players facing
« Reply #4 on: February 08, 2017, 08:13:50 PM »
Thanks for the advice. I finally managed to get it to behave exactly the way I want it to.

I'm using physics 'AddForce' to the projectile and transform.translate to move the ship. Eventually I'd like to use physics to move the player ship but I've already dumped too much time into basic movement/shooting I just want to move on. I'll come back to it eventually.

The only thing I'm having trouble with now is getting the velocity of the player ship, setting the projectiles speed to that and then adding a force amount of my choosing.

Edit:I've now got the shooting/firing system working the way I'd like it to for right now, thanks everyone!
« Last Edit: February 08, 2017, 08:19:36 PM by lacju »