|
| 10 May 2015 06:53 PM |
I'm trying to make a gui where if the mouse enters the gui, a brick moves forward across the map with the camera following it.
However, I want the brick to stop once the mouse leaves the gui. So far, I've got this:
repeat wait() until game.Workspace.Camera local target = game.Workspace.CameraStarterPart local camera = game.Workspace.Camera camera.CameraSubject = game.Workspace.CameraStarterPart camera.CameraType = "Scriptable" local angle = 0
function Mouseenter() while true do game.Workspace.CameraStarterPart.CFrame = game.Workspace.CameraStarterPart.CFrame+Vector3.new(1,0,-1) camera.CoordinateFrame = CFrame.new(target.Position) * CFrame.Angles(30.4, angle+150.3, 0) wait(0.001) end end
function Mouseleave() game.Workspace.CameraStarterPart.CFrame = CFrame.new(game.Workspace.CameraStarterPart.Position) camera.CoordinateFrame = CFrame.new(target.Position) * CFrame.Angles(30.4, angle+150.3, 0) wait() end
script.Parent.MouseEnter:connect(Mouseenter) script.Parent.MouseLeave:connect(Mouseleave)
I've been stuck on this for a while. Right now, when the mouse enters the GUI, the brick takes off and keeps going, not stopping when it leaves the GUI.
Any help would be great, thanks! |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
|
| 10 May 2015 07:20 PM |
Use body velocities.
Goodness Gracious that Booty is Spacious! |
|
|
| Report Abuse |
|
|
|
| 10 May 2015 07:20 PM |
I would think it would be caused by the infinite loop(while true do), perhaps make a local variable "mouseIsOnGUI" or something and say "while mouseIsOnGUI do", then have something to set mouseIsOnGUI to false in the mouseleave method, that would be my best guess but I'm a little new to scripting.
--Gun Fighter Extraordinaire, InnovatedFighting-- --Gun Fighter Extraordinaire, InnovatedFighting-- |
|
|
| Report Abuse |
|
|
|
| 10 May 2015 07:22 PM |
| Body Velocity doesn't run as smooth as CFrame does, especially with the camera. |
|
|
| Report Abuse |
|
|
|
| 10 May 2015 07:24 PM |
@inno
The trouble is, what do I make MouseIsOnGUI?
And I still have a loop problem, I would need a break somewhere in here. |
|
|
| Report Abuse |
|
|
Ice7
|
  |
| Joined: 26 Jun 2007 |
| Total Posts: 1058 |
|
|
| 11 May 2015 02:07 PM |
The MouseEnter event fires every time the Gui contains the mouse's coordinates and by adding a loop inside you are blocking the event from firing again until the loop is finished.
If you insist on using CFrame, then handle the the loop in a separate thread. You can do this using the spawn() function.
local Moving=false Gui.MouseEnter:connect(function() Moving=true spawn(function()
while (Moving) do P.CFrame = stuff Camera.CoordinateFrame = stuff end)
end)
Gui.MouseLeave:connect(function() Moving=false Camera.CoordinateFrame = stuff end)
Rather than |
|
|
| Report Abuse |
|
|
Ice7
|
  |
| Joined: 26 Jun 2007 |
| Total Posts: 1058 |
|
|
| 11 May 2015 02:08 PM |
| Rather than continously updating the camera, you could just alternatively set the Camera Subject unless you want to change the focus over time |
|
|
| Report Abuse |
|
|