playMaker

Author Topic: Getting objects move distance forward/back, ignoring left/right  (Read 2117 times)

Mupp

  • Full Member
  • ***
  • Posts: 167
How can I get an objects total move distance forward/back(including the distance it moved up/down), but ignoring the distance it moved left/right during one frame?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Getting objects move distance forward/back, ignoring left/right
« Reply #1 on: August 24, 2021, 04:28:36 PM »
Hi.
On start move, get position, then get current position and calculate current pos - start pos. and the use Float Abs to set negative results to positive.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Getting objects move distance forward/back, ignoring left/right
« Reply #2 on: August 24, 2021, 04:49:50 PM »
Hi.
On start move, get position, then get current position and calculate current pos - start pos. and the use Float Abs to set negative results to positive.
No, you misunderstand, I don't want to know the total distance, just forward/backward.
You know when in a FPS you run diagonally for example, you hold up and right/left or down and right/left.
I want to shave off the right/left distance the object move this frame and only get the distance it moved along in its forward/backward direction that it had at the start of the frame.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Getting objects move distance forward/back, ignoring left/right
« Reply #3 on: August 24, 2021, 05:17:16 PM »
Hi.
You can do something similar as my previous answer.

Get Position (x,y,z) ) and store (Last Frame)
Then do Next Frame Event
Then Get Position Again (x,y,z) (Current Frame)

then do float operator for the axis you need.

for example Current Frame X - Last Frame X
Then Float Abs if you want it always to be a positive value


Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Getting objects move distance forward/back, ignoring left/right
« Reply #4 on: August 24, 2021, 05:40:33 PM »
Hi.
You can do something similar as my previous answer.

Get Position (x,y,z) ) and store (Last Frame)
Then do Next Frame Event
Then Get Position Again (x,y,z) (Current Frame)

then do float operator for the axis you need.

for example Current Frame X - Last Frame X
Then Float Abs if you want it always to be a positive value
No that can't be right. If you were to run straight across the X axis you would get 0 since it would never change. You must account for the rotation of the object and since I use translate to move it takes care of that.
Forward/backward of my object is its Z axis and I want to check how far the object moved just along this line no matter what rotation my object has, excluding the distance moved from the X axis(left/right) and all I have to use are the world positions from this and previous frame.