playMaker

Author Topic: Adding force in the direction of an object  (Read 1573 times)

Benjhs

  • Playmaker Newbie
  • *
  • Posts: 2
Adding force in the direction of an object
« on: July 17, 2017, 10:24:18 PM »
Fairly beginner - working with an FPS character controller trying to add force towards an object the player throws.

Currently when you press 'e', the player throws a cube in the direction the player is looking.
When the player presses 'e' again, I want the player to have force applied in the direction the cube is in, like they're being pulled towards it.
ie, if you throw the cube in the air and press 'e' again, the player is pulled towards it.
The cube is then returned to the player and they can repeat the action.

I know there must be a simple solution to it, though being a beginner I just can't figure out how to use the direction of the cube from the player as the direction of the Add Force.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Adding force in the direction of an object
« Reply #1 on: July 17, 2017, 11:21:52 PM »
I think the biggest problem might be is if you move the player (so you cannot just simply add the opposite force).

I wrote a nice easy action that can calculate the direction between game objects (player and the cube). Using that direction, it can help you figure out which way to apply the force. (Make sure to click the normalized direction tick box and use that one).

Then multiple the force as necessary (usually needs a decent number). Action "Vector 3 multiple".

Then add to the add force action in the direction variable.

Benjhs

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Adding force in the direction of an object
« Reply #2 on: July 18, 2017, 01:06:02 AM »
Thanks for the speedy response!
I think I understand, I'll have a crack and let you know how it goes. Cheers!