playMaker

Author Topic: AddForce relative to direction. [SOLVED]  (Read 1794 times)

MajorIdea

  • Full Member
  • ***
  • Posts: 111
    • View Profile
AddForce relative to direction. [SOLVED]
« on: December 31, 2012, 08:52:35 AM »
Hi, is there a way of using playmaker to make a propeller that pushes the player in the direction the propeller is facing?

The way I have it now I'm using an addforce to the player in world space. I have to tweak the values for each one to make it go in the direction it should. But thats a terrible system and it doesn't work if the propeller is on something that rotates and changes direction.

I've looked into the AddForce expample in the testlabs but that seems to be specific to mouse picking and cant figure out how to adapt it http://www.hutonggames.com/sampleScenes/AddForce/AddForce.html

Any help would be greatly appreciated.
Happy 2013!
« Last Edit: January 02, 2013, 11:11:12 AM by MajorIdea »

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: AddForce relative to direction.
« Reply #1 on: December 31, 2012, 09:43:22 AM »
"transform Direction" is likely what you're looking for. transform a local force direction from the propellor to a global one which you can then apply on your player as force.
Best,
Sven

MajorIdea

  • Full Member
  • ***
  • Posts: 111
    • View Profile
Re: AddForce relative to direction.
« Reply #2 on: January 02, 2013, 10:20:32 AM »
Err, so I've been trying to figure out how to do that (or even what that meant) with no luck. Any additional pointers? How do I transform a local force direction using that?

Thank you for the support  :)

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: AddForce relative to direction.
« Reply #3 on: January 02, 2013, 10:36:07 AM »
create a vector3 variable called DirectionOrig and then one called DirectionCur.
then use the transformDirection action in your FSM. Set the gameObject to your propellor gameObject. Set the direction value to your DirectionOrig and set the output vector3 to your DirectionCur. Check Every frame. Now use your Direction Cur in an addForce action with the target being your character and the space being world.

Now all you need to do is to set the Direction Orig to something that makes it point towards the axis the propellor should fly. Like, if it points up the vector3 would be 0,1,0.  Make sure you check it in local/self space.

This makes it recalculate the direction from local space of the propellor into global space, which you can then globally(world) apply on any other gameObject. If the propellor rotates, the directionOrig will put out a different direction.

Do you want pics? It's actually quite simple once you've understood the principle of those transform actions. They can be a real pain in complex situations :D
« Last Edit: January 02, 2013, 10:38:09 AM by kiriri »
Best,
Sven

MajorIdea

  • Full Member
  • ***
  • Posts: 111
    • View Profile
Re: AddForce relative to direction.
« Reply #4 on: January 02, 2013, 10:42:57 AM »
That does sound pretty complicated, but I shall do my best! You've described it spectacularly so no pics are needed xD

I'll let you know how it goes. Thanks a bunch!

MajorIdea

  • Full Member
  • ***
  • Posts: 111
    • View Profile
Re: AddForce relative to direction.
« Reply #5 on: January 02, 2013, 11:10:40 AM »
IT LIVES!

I had to uncheck the Every Frame on the Transform Direction because the force is applied when the player is On Trigger Stay, so it wouldn't go back to check if it was still on the triggers and the force would only be applied in one frame (cant have the Every Frame checked on the add force because that makes it go forever).

I don't think I need it since It will reload the action every time the player enters the propeller trigger and the propelled itself rotates rather slowly.

So yea. Thanks kiriri! You the man.  :D