Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Thore on September 26, 2018, 05:05:35 PM

Title: GetRelativeDirection2D
Post by: Thore on September 26, 2018, 05:05:35 PM
While learning to code some more, I wanted to do an AddExplosion2D version and ended up making a more generalized action that may be useful. I am almost certain something like this exists, but didn't find it.

GetRelativeDirection2DEvent
You provide an origin GameObject, and a target. It calculates the direction and distance, as X and Y separated. When the target is left or down from origin, it returns the distances as negative numbers.

Note, there is also GetDistance (in Ecosystem at least), which tells you the direction in a straight line from origin to target.

(https://i.imgur.com/Zws6yRR.png)

Store Directions: stores the float values for later use. Note that left and down return negative values. When you don't want this, use Float Abs in a later step. Though consider if this is the right action for you.

Store isRight & isUp: convenient bools to use later. E.g. with Bool Test when isUp is false, you know the target is downwards.

Every Frame: what it says on the tin. As is standard, will ignore events. I have made a twin action (GetRelativeDirection2D) that doens't have the events, which you may prefer.

Preference: Allows you to set how to "interpret" the data. Also see my graphic attached.

As Usual
I'm not a coder, it may or may not be the best way to do this. However, it does the trick nicely. There's an alternative method out-commented to also allow to switch local/world space, which I adapted from another action. However, that didn't make sense to me, so I didn't use it.

If someone wants to improve on it, make more actions based on this, test it, and upload it to Ecosystem, feel free! :)
Title: Re: GetRelativeDirection2D
Post by: Thore on September 26, 2018, 05:36:40 PM
And here's a quick test scene (does not contain the actions, add GetRelativeDirection2DEvent before you start this).
Title: Re: GetRelativeDirection2D
Post by: menosa on September 27, 2018, 10:31:11 AM
 I will check them out, if think this is just what I needed. cheers  :)
Title: Re: GetRelativeDirection2D
Post by: craigz on September 27, 2018, 11:44:10 AM
This is great Thore :D thanks for making this :)

Question! What's the usecase that you've been using it for if you dont mind me asking? :D
Title: Re: GetRelativeDirection2D
Post by: Thore on September 27, 2018, 12:03:57 PM
This is great Thore :D thanks for making this :)

Question! What's the usecase that you've been using it for if you dont mind me asking? :D

As a side project for fun, I work on a 2D platformer type of game. I originally started the action for a (cartoon) bomb to add force based on where the targets are located, relative to the explosive. I use it there, though I'd like to have a better AddExplosiveForce2D version, which I started making, but am stuck (thread in this help subforum, chime in!) (https://hutonggames.com/playmakerforum/index.php?topic=19497.0).