generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Pathfinding and Movement

Previous Thread :: Next Thread 
ShadowOfCrimson is not online. ShadowOfCrimson
Joined: 14 Dec 2009
Total Posts: 2153
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 is not online. 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
ShadowOfCrimson is not online. ShadowOfCrimson
Joined: 14 Dec 2009
Total Posts: 2153
11 May 2015 09:42 AM
Yeah sort of, like movement tweens :)
Report Abuse
eLunate is not online. 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
ShadowOfCrimson is not online. ShadowOfCrimson
Joined: 14 Dec 2009
Total Posts: 2153
11 May 2015 09:49 AM
does that work with vector3 values?
Report Abuse
eLunate is not online. 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
ShadowOfCrimson is not online. ShadowOfCrimson
Joined: 14 Dec 2009
Total Posts: 2153
11 May 2015 09:52 AM
Sweet thanks eLunate :)

Btw, do you remember me from months ago?
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
11 May 2015 09:54 AM
I think so
Report Abuse
ShadowOfCrimson is not online. ShadowOfCrimson
Joined: 14 Dec 2009
Total Posts: 2153
11 May 2015 09:55 AM
You and I basically ran Scripting Helpers for a while, when it was still there.
Report Abuse
ShadowOfCrimson is not online. ShadowOfCrimson
Joined: 14 Dec 2009
Total Posts: 2153
11 May 2015 10:08 AM
Oh and your script works like a charm, thanks very much :D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image