|
| 11 May 2015 09:18 AM |
Hello Scripting Forums, I'm working on a script right now and I've been having a bit of an issue trying to get this calculation right, I think I'm making it more or less complicated than it has to be or I'm doing it the wrong way.
What I'm doing right now is I'm using a hopper bin with a local script to control the movement of a ball right now. The ball is anchored and has a script inside it that makes it move with a script by changing its position when it's enclosed Vector3 Value has its value changed (in order to later add a movement request system).
So what I'm doing with the script is taking the distance from where I click with my mouse using the Bin from the position of the ball where it is located. I then try to step out the ball's movement based on the distance and move it with a for next loop from location to where i clicked.
Here's that:
local p=script.Parent function changed() local distance=math.floor((p.Position-p.Pos.Value).magnitude) print("dist: " .. distance) local position={} position[1]=(p.Pos.Value.x-p.Position.X)/distance position[2]=p.Position.Y position[3]=(p.Pos.Value.z-p.Position.Z)/distance print(position[1]) print(position[3]) for x= 1,distance do wait(.1) p.Position = Vector3.new(position[1]*x,position[2],position[3]*x) end end
p.Pos.Changed:connect(changed)
--Can anyone tell me what I'm getting wrong in my calculations for this?
What I find is the ball relocates to center of the map each movement and doesn't really end up where i want it to go. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 11 May 2015 09:41 AM |
| Are you trying linear tweening? I have those for both constant speed and constant time if that's the case... |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 09:42 AM |
| Yeah sort of, like movement tweens :) |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 11 May 2015 09:47 AM |
diff = end-start; dist = diff.magnitude diff = diff.unit local t = 0; while t < dist do t = t+wait() object.Position = start+diff*t end object.Position = end |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 09:49 AM |
| does that work with vector3 values? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 11 May 2015 09:51 AM |
Yes.
Use t = t+wait()*speed where speed is the studs/s |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 09:52 AM |
Sweet thanks eLunate :)
Btw, do you remember me from months ago? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
|
| 11 May 2015 09:55 AM |
| You and I basically ran Scripting Helpers for a while, when it was still there. |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 10:08 AM |
| Oh and your script works like a charm, thanks very much :D |
|
|
| Report Abuse |
|
|