CarlosMX
|
  |
| Joined: 30 Apr 2011 |
| Total Posts: 791 |
|
|
| 03 Jul 2014 06:22 PM |
hey guys, im working on a RTS and its working fine, but I've noticed that when I click somewhere far away for the mini soldiers to move there, they go extremely fast, but when I click somewhere close to their original location, they go really slow... How would I fix this?
local pos = Vector3.new(mouse.Hit.p.X, 0, mouse.Hit.p.Z) for i = 1, 100 do wait() if game.Workspace:findFirstChild(SOLDIER)~=nil then game.Workspace:findFirstChild(SOLDIER):TranslateBy((pos-game.Workspace:findFirstChild(SOLDIER).Select.CFrame.p)/100) end
|
|
|
| Report Abuse |
|
|
|
| 03 Jul 2014 06:32 PM |
| Because the (1, 100) can be different for each distance. |
|
|
| Report Abuse |
|
|
CarlosMX
|
  |
| Joined: 30 Apr 2011 |
| Total Posts: 791 |
|
|
| 03 Jul 2014 07:41 PM |
Ok, so I've changed the to repeat until loop. But it still does the same thing.. How can I fix this? It also does the same thing with While loops aswell.
local pos = Vector3.new(mouse.Hit.p.X, 1 ,mouse.Hit.p.Z) repeat wait() if game.Workspace:findFirstChild(SOLDIER)~=nil then game.Workspace:findFirstChild(SOLDIER):TranslateBy((pos-SOLDIER).Select.CFrame.p)/100) end
until (SOLDIER).Select.Position - pos).magnitude <= 5 or
(SOLDIER) ==nil) |
|
|
| Report Abuse |
|
|
|
| 03 Jul 2014 07:48 PM |
(pos-SOLDIER).Select.CFrame.p)/100)
You are dividing by 100 still.
Divide by the initial distance. |
|
|
| Report Abuse |
|
|
CarlosMX
|
  |
| Joined: 30 Apr 2011 |
| Total Posts: 791 |
|
|
| 03 Jul 2014 07:57 PM |
| So divide by the magnitude between mouse click and soldier's position? |
|
|
| Report Abuse |
|
|
|
| 03 Jul 2014 08:03 PM |
| The initial soldiers position, unless you want something that gets exponentially faster. |
|
|
| Report Abuse |
|
|
CarlosMX
|
  |
| Joined: 30 Apr 2011 |
| Total Posts: 791 |
|
|
| 03 Jul 2014 08:06 PM |
| That works better, thanks. |
|
|
| Report Abuse |
|
|