playMaker

Author Topic: How to get a center objects relative position  (Read 811 times)

Mupp

  • Full Member
  • ***
  • Posts: 167
How to get a center objects relative position
« on: February 24, 2021, 07:06:58 PM »
How can I get an objects relative position if it's the middle object of 3 objects in a line? I want this value as a float so I can use it as the amount in a LERP action.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: How to get a center objects relative position
« Reply #1 on: February 25, 2021, 03:03:00 AM »
Relative to what, World space?

And position is either Vector2 or Vector3 / X, Y, Z , which variable is the float going to affect?

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: How to get a center objects relative position
« Reply #2 on: February 25, 2021, 09:16:05 AM »
Um, what's unclear exactly? Have you never used a LERP action? You have 2 points and you move a 3rd between then using a float as its relative position between them.

wetcircuit

  • Full Member
  • ***
  • Posts: 158
    • wetcircuit.com
Re: How to get a center objects relative position
« Reply #3 on: February 25, 2021, 11:11:12 AM »
break it down into steps (I see 3 steps)

1. get the difference (actual distance) between start A and end B objects
*probably difference=Abs(B-A)

2. get the difference between the middle object Mid from the start A
*probably midDifference=Abs(Mid-A)

3. divide the 2nd result by the 1st
*probably T=midDifference/difference

T gives you the value to set the Lerp.
« Last Edit: February 25, 2021, 11:21:17 AM by wetcircuit »

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: How to get a center objects relative position
« Reply #4 on: February 25, 2021, 11:42:09 AM »
I don't know what you mean by "probably", but thanks. I'll give this a try.