huner2
|
  |
| Joined: 27 Apr 2008 |
| Total Posts: 1681 |
|
|
| 20 Feb 2012 11:10 AM |
This script is supposed to make this brick continue moving untill equalling another bricks position then moving the other way.But it just keeps going the one way and just passes through the brick.No output.How can I fix this?
MovingBrick = script.Parent TargetBrick1 = script.Parent.Parent.Table.Wall1 TargetBrick2 = script.Parent.Parent.Table.Wall2 Moving1 = true Moving2 =false
while true do wait() if Moving1 == true and Moving2 == false then Moving1 = false repeat wait(1) MovingBrick.CFrame = MovingBrick.CFrame * CFrame.new(1,0,0) until MovingBrick.CFrame == TargetBrick1.Position Moving2 = true elseif Moving1 == false and Moving2 == true then Moving2 = false repeat wait(1) MovingBrick.CFrame = MovingBrick.CFrame * CFrame.new(-1,0,0) until MovingBrick.CFrame == TargetBrick2.Position Moving1 = true end end |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 11:13 AM |
Use a loop without 'until'.
while true do if position == second placement then --move brick to first placement end if position == first placement then --move brick to second placement end wait() end
Ta da. |
|
|
| Report Abuse |
|
|
huner2
|
  |
| Joined: 27 Apr 2008 |
| Total Posts: 1681 |
|
|
| 20 Feb 2012 11:16 AM |
| I tried this already and it did not work and neither did the one I posted. |
|
|
| Report Abuse |
|
|
asianpunk
|
  |
| Joined: 15 Dec 2010 |
| Total Posts: 150 |
|
|
| 20 Feb 2012 11:19 AM |
MovingBrick = script.Parent TargetBrick1 = script.Parent.Parent.Table.Wall1 TargetBrick2 = script.Parent.Parent.Table.Wall2 Moving1 = true Moving2 =false
while true do wait() if Moving1 == true and Moving2 == false then Moving1 = false repeat wait(1) MovingBrick.CFrame = MovingBrick.CFrame * CFrame.new(1,0,0) until MovingBrick.CFrame.p == TargetBrick1.Position Moving2 = true elseif Moving1 == false and Moving2 == true then Moving2 = false repeat wait(1) MovingBrick.CFrame = MovingBrick.CFrame * CFrame.new(-1,0,0) until MovingBrick.CFrame.p == TargetBrick2.Position Moving1 = true end end
--[=[ You use a condition which test if CFrame = Postion it will return false for ever: Use CFrame.p (return the Vector3 Position of the CFrame) ]=] |
|
|
| Report Abuse |
|
|
huner2
|
  |
| Joined: 27 Apr 2008 |
| Total Posts: 1681 |
|
|
| 20 Feb 2012 11:22 AM |
| It didn't help, it still did the same thing. |
|
|
| Report Abuse |
|
|
huner2
|
  |
| Joined: 27 Apr 2008 |
| Total Posts: 1681 |
|
| |
|
|
| 20 Feb 2012 04:20 PM |
This is happening because Roblox does not update fast enough to detect the exact moment the CFrames are exactly equal (they only get very close). You will have to add in some error, so if you are doing this on the x plane and the target brick is A and the moving brick is B....
while B.CFrame.x <= A.CFrame.x do B.CFrame = B.CFrame + Vector3.new(1,0,0) wait() end --when this while loop breaks it will have equalled or passed A's "x" position, so now set it in the opposite direction while true do B.CFrame = B.CFrame - Vector3.new(1,0,0) wait() end
|
|
|
| Report Abuse |
|
|
huner2
|
  |
| Joined: 27 Apr 2008 |
| Total Posts: 1681 |
|
|
| 20 Feb 2012 04:33 PM |
| Oh,well thank you, but I also need to to reverse back the other way when it reaches the other position. |
|
|
| Report Abuse |
|
|