playMaker

Author Topic: Move object between to vector3 via a float?[SOLVED]  (Read 3380 times)

derkoi

  • Full Member
  • ***
  • Posts: 187
Move object between to vector3 via a float?[SOLVED]
« on: August 17, 2013, 12:33:56 PM »
I have 2 vector3 positions and I need to move an object between them but be able to control the movement via a slider/float value, so 100 would be at point B and 0 would be at point a, 50 would be in the middle and so on.

Any ideas how I could do this please?
« Last Edit: September 09, 2013, 03:12:51 AM by jeanfabre »

ltj

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Move object between to vector3 via a float?
« Reply #1 on: August 17, 2013, 04:10:25 PM »
Not a complete solution, but I'll try to help get the ball rolling.

I didn't come up with a slider, but let's assume for now there's already a working one. You said the position is between 0-100, but for this I'll use 0-1 and call it x. (If you want to stick with a percent, it just requires dividing or multiplying somewhere along the line.) So, you position A at x=0 and B at x=1. And at 0<x<1, when the slider is in between, you will be at C.

Start of by getting the vector between A and B, I'll call it AB. So you'll need to create a vector3 for each, as well as C.
To get AB use "set vector value" of AB  to be the same as B, then use "subtract Vector3" to subtract A from AB, to give your actual AB value. (ie B-A=AB)
So, now if you multiply AB by some number between zero and one and add it to A, you will get a position between A and B.
So, use "Vector 3 multiply" and multiply by your int, x.
Then use "Vector 3 add" to add to A. i.e. A+xAB=C
Then "set position" of your object to C.


Seemed to work in my testing. But it sure reminded me how rusty my geometry is. Hope it helps at all.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Move object between to vector3 via a float?
« Reply #2 on: August 19, 2013, 04:18:55 AM »
Hi,

 this is called lerping. Simply use the action "Vector 3 lerp"

store the result and use that result to set the position of your object.

now, if you modify the "Amount" of lerp from 0 to 1 you will move between your "from" position and "to" position.

so bind your slider to modify the lerp amount and you are done.

Bye,

Jean

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Move object between to vector3 via a float?
« Reply #3 on: August 20, 2013, 02:58:25 PM »
Thanks guys  :D