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 » Scripting Helpers
Home Search
 

Re: For loop goes wrong..

Previous Thread :: Next Thread 
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
28 Mar 2012 11:28 AM
for i = 1,5,1 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
wait(2)
for i = 5,1,-1 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end

I want to ask, when I do this it both backs up. Meaning, the camera backs up once, then backs up again. I want it to back up once, and go front once. You knwo why?
Report Abuse
crazyblox is not online. crazyblox
Joined: 16 Mar 2008
Total Posts: 6139
28 Mar 2012 11:35 AM
for i = 1,5,1 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
wait(2)
for i = -5,-1,1 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
28 Mar 2012 11:37 AM
Note: When the for loop goes in increments of "1", you don't need to put it there ("for i = 1, 5, 1" can be simplified).
Also, "i" is still positive in both of them. I don't know much about it but I assume you would do something like this (pardon the poor syntax that is going to occur):

camerapositon = game.Workspace.CurrentCamera.Focus -- Would this be ".CFrame"
-- or ".Position"? I don't really know much about cameras.
for i = 1, 5 do
game.Workspace.CurrentCamera.Focus = CFrame.new(cameraposition - CFrame.new(0,i,0)
end

Basically, you could try subtracting it instead. Sorry I don't know the exact way to do so.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
28 Mar 2012 11:38 AM
Still moved back twice. Didn't move back once.
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
28 Mar 2012 11:38 AM
Oh, right. I forgot you could make the numbers in the for loop negative.
Just do that then. The problem was "i" being positive, just in reverse order.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
28 Mar 2012 11:43 AM
@solo

Didn't work.
Report Abuse
crazyblox is not online. crazyblox
Joined: 16 Mar 2008
Total Posts: 6139
28 Mar 2012 11:44 AM
Im doing blind guesses because im a awful reader/listener.

for i = 1,5 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
wait(2)
for i = 5,1,-1 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
28 Mar 2012 11:47 AM
Still same thing. Moved back twice.
Report Abuse
crazyblox is not online. crazyblox
Joined: 16 Mar 2008
Total Posts: 6139
28 Mar 2012 11:49 AM
No, it doesnt. i just tested it.
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
28 Mar 2012 11:51 AM
Alright.
My first post was just concept, I don't know the camera very well and can't open studio right now.

Does it have any form of "position" value or the such?

Hmm, try taking this and changing it if it doesn't work:

for i = 1,5, do
game.Workspace.CurrentCamera.Focus = game.Workspace.CurrentCamera.Focus + CFrame.new(0,1,0)
wait(.15)
end
wait(2)
for i = 1, 5 do
game.Workspace.CurrentCamera.Focus = game.Workspace.CurrentCamera.Focus + CFrame.new(0, -1, 0)
wait(.15)
end

I think it'd be easier to just do +1 -1, unless you are specifically going to a certain place, in which you would just define all three coordinates.

Sorry about not being able to do this.
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
28 Mar 2012 11:52 AM
Yeah, I'm confused as to why the negative for loop didn't work (-5, -1).
Did you make sure you cut and pasted it again so that it was running the new script?
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
28 Mar 2012 11:54 AM
@crazyblox

Hmm..Really? Maybe it's my code...See anything wrong here?

wait(2)
game.Players.LocalPlayer.PlayerGui.IntroGui.ChildRemoved:connect(function(meow)
game.Workspace.CurrentCamera.CameraSubject = game.Workspace.Box.View
game.Workspace.CurrentCamera.CameraType = "Follow"
for i = 1,5,1 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
wait(2)
for i = 5,1,-1 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
end)
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
28 Mar 2012 11:55 AM
"for i = 5,1,-1 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
end)"
You didn't make it negative like he said.
"for i = 5, 1, -1 do" should be "for i = -5, -1, 1 do"
The negatives are the numbers that "i" is, not the step.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
28 Mar 2012 11:58 AM
for i = -5,-1,1 do

When I said that, it moved back, not front.
Report Abuse
crazyblox is not online. crazyblox
Joined: 16 Mar 2008
Total Posts: 6139
28 Mar 2012 12:02 PM
I dont know what is causing that problem. sorry.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
28 Mar 2012 12:07 PM
Anyone?
Report Abuse
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
28 Mar 2012 12:30 PM
Why make it overcomplicated? Duplicate loop, reverse the i.

for i = 1,5 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,i,0)
wait(.15)
end
wait(2)
for i = 1,5 do
game.Workspace.CurrentCamera.Focus = CFrame.new(0,-i,0)
wait(.15)
end
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
28 Mar 2012 12:36 PM
Change the CoordinateFrame. Not the focus.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
28 Mar 2012 12:36 PM
Didn't work...
Report Abuse
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
28 Mar 2012 12:41 PM
Oh wait. I thought you had point * CFrame.new(0,i,0).


--

Flood and word that breaks the rules in my post if I post my snippet. Woot..
Report Abuse
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
28 Mar 2012 12:43 PM

game.Workspace.CurrentCamera.Focus = CFrame.new(0,0,0)

for i = 1,5,1 do
game.Workspace.CurrentCamera.CoordinateFrame = game.Workspace.CoordinateFrame * CFrame.new(0,1,0)
wait(.15)
end
wait(2)
for i = 1,5,1 do
game.Workspace.CurrentCamera.CoordinateFrame = game.Workspace.CoordinateFrame * CFrame.new(0,-1,0)
wait(.15)
end

The above should work.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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