playMaker

Author Topic: [SOLVED] Add Force in player direction  (Read 11268 times)

Intoccabile

  • Playmaker Newbie
  • *
  • Posts: 4
[SOLVED] Add Force in player direction
« on: November 01, 2012, 01:54:41 AM »
Hi All,

I am following a simple tutorial from the tornadotwins on creating a game ( However I want to use playmaker to do everything that they do with scripting. I have a controlable character (with mouse look and strafing etc.) and I have created a prefab and a spawn point for the prefab. I have created the fsm to create the object in the correct position.

I am having issues adding force to the object in the direction of the player. The object spawns correctly and I can add force, however only in set directions. I need to be able to use the player direction and multiply the force.

When scripting you use the transform.forward * 200

Does anyone know how to do this with playmaker??

Thanks in advance!
« Last Edit: November 05, 2012, 01:21:28 AM by Intoccabile »

krakov73

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Add Force in player direction
« Reply #1 on: November 01, 2012, 05:33:15 PM »
Sorry if i'm wrong (i'm somewhat newb) but try sticking your 200 value in the Z axis of the addforce action, that should be the equivilant of transform.forward.

DARK_ETERNAL

  • Full Member
  • ***
  • Posts: 110
Re: Add Force in player direction
« Reply #2 on: November 01, 2012, 06:44:11 PM »
Unfortunately, Playmaker does not support a Vector3.Forward direction. You can set the Z axis of your character rotation to a value to add force. Positive Z values are the Forward vector. (Unity Vector3.Forward is equal to Vector3 (0,0,1) ), as krakov73 says.
Check out our new game: Nitro Chimp. Now live in App Store!

Trailer:
Download: https://itunes.apple.com/app/nitro-chimp/id557150450?l=en&mt=8

Intoccabile

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Add Force in player direction
« Reply #3 on: November 01, 2012, 08:21:21 PM »
Hi guys,

Thanks for the replies. However I have tried this. As mentioned in the OP I was able to add force and have the object shoot off in a direction however it always seems to go in the same direction not the Z axis of the player.

Is there something I am doing wrong here?

Intoccabile

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Add Force in player direction
« Reply #4 on: November 02, 2012, 02:20:33 AM »
Ok i think the actual issue is that I cant get the object that I am creating to point (z axis) in the direction of the players z axis. How do I get the players z axis and set the objects z axis to this?

I have tried get axis vector and get axis. But cant seem to set the right rotation/axis of the object created.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add Force in player direction
« Reply #5 on: November 02, 2012, 05:57:06 AM »
Hi,

 you simply need to set the force to be added to "self" instead of to the world" space.

Please find attached a working sample of a cube you control by adding force and torque. as you apply forces, you'll see that it properly add forces to the z axis of the cube where ever is the cube looking.

bye,

 Jean
« Last Edit: February 17, 2014, 11:11:37 AM by jeanfabre »

kuhnen

  • Playmaker Newbie
  • *
  • Posts: 3
Re: [SOLVED] Add Force in player direction
« Reply #6 on: February 15, 2014, 07:49:11 PM »
The attachment on this reply doesn't open on the newer version of Unity. Any chance we can get an updated version?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: [SOLVED] Add Force in player direction
« Reply #7 on: February 17, 2014, 11:11:54 AM »
Hi,

 try now, I made it as a package, it should work better now.

bye,

 Jean

MattyWS

  • Junior Playmaker
  • **
  • Posts: 90
Re: [SOLVED] Add Force in player direction
« Reply #8 on: July 21, 2016, 04:53:12 PM »
Sorry to rez the topic but the example attached doesn't seem to have any functionality and I'm at a loss. :( I have a 2D game where you control a spaceship, so far I can rotate it but I cannot add force to the direction it's facing locally. I tried the example above to no avail (as I mentioned, the cube doesn't move). Any help would be lovely.

I've noticed the Add force action for 3D has a local/world space option but Add Force 2D doesnt~

« Last Edit: July 21, 2016, 04:57:53 PM by MattyWS »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: [SOLVED] Add Force in player direction
« Reply #9 on: July 22, 2016, 03:40:55 AM »
Hi,

 good point. It's odd. I am pretty sure I covered that at one point during the support of physic2d... oh well...

 Please find a new action attached to this post. I'll see with Alex, but I think it will make it in the next update of PlayMaker, it should be part of the official set of actions.

 Bye,

 Jean

MattyWS

  • Junior Playmaker
  • **
  • Posts: 90
Re: [SOLVED] Add Force in player direction
« Reply #10 on: July 22, 2016, 07:20:49 AM »
Thanks! I'll be testing this when I get back later tonight. ^^

Rispetto

  • Playmaker Newbie
  • *
  • Posts: 3
Re: [SOLVED] Add Force in player direction
« Reply #11 on: January 10, 2019, 02:20:10 AM »
Hey folks, I'm necroing this thread to solve the problem once and for all.

So you have an object.. in my case a bullet.. and you want it to travel 'forward' no matter what direction it's facing. The answer is this:

You must transform the object's local direction into the world direction. So if you apply force to the object's local direction of X, it will travel to the right. If you rotate it, it will always travel to the right of the sprite. The problem is the game doesn't look at the object's orientation when applying the force. I think I explained that right..

Anyway.. you need to use two actions: "Transform Direction" and "Add Force 2D". Under Transform Direction, save the result in a Vector3 local variable, then use that local variable as the direction of the Add Force 2D Vector3.

It looks like this:



Hope that helps!