playMaker

Author Topic: does this action exist? get position between two objects  (Read 992 times)

strange_aeons

  • Junior Playmaker
  • **
  • Posts: 62
does this action exist? get position between two objects
« on: July 05, 2020, 10:51:13 PM »
is there is a action that gets a objects position relative to another objects local space. basicly i need to know whether cube B is on cube A's left or right side every frame, regardless of its position and orientation in the world space as both are parented to cube C which moves and rotates on its own.

at the moment i an using "Get Distance" and that works as long as cube B is on cube A's right hand side.

is there a way to get the local space position of where cube B is in cube A's local space?
« Last Edit: July 07, 2020, 01:42:29 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: does this action exist?
« Reply #1 on: July 06, 2020, 01:50:26 AM »
Hi,

 yes, few ways to achieve this:

get A position in a vector
get B position in a vector
substract A to B, you get the vector between A and B

even though the positions are expressed in world space, substract A to B gives you the relative position, Are you ok with that?

now youc an do that differently:

get A position
use the action InverseTransformPoint using B as the GameObject and A position as the world positionm, you will get the relative position of A compare to B.

Bye,

 Jean

strange_aeons

  • Junior Playmaker
  • **
  • Posts: 62
Re: does this action exist?
« Reply #2 on: July 06, 2020, 02:50:20 AM »
Hi jean and thanks for your suggestions. i tried the first method and saw different results than i expected. im not even sure how to go about the second suggestion with what i have setup already. but it sounds like theres no action that will do what "get distance" does but give me a negative float when cube B passes on to the left of cube A

strange_aeons

  • Junior Playmaker
  • **
  • Posts: 62
Re: does this action exist?
« Reply #3 on: July 06, 2020, 08:31:54 PM »
i hate not understanding something, but i managed to get the result i wanted by applying both of your suggestions. im not sure if both were necessary or something is redundant. maybe if i had to recreate the effect. thanks again, that really helped

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: does this action exist? get position between two objects
« Reply #4 on: July 07, 2020, 01:44:48 AM »
Hi,

 you may need to look into tutorials on pur 3d mathematics and vectors, It's hard to find good ones, I must admit, so experimenting is necessary, but getting some basic knowledge is also critical to not pull your hairs...

here's Unity's own attempt at getting the basics covered:

https://docs.unity3d.com/Manual/UnderstandingVectorArithmetic.html

Bye,

 Jean