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
 

How would I stop this GUI Movement from glitching?

Previous Thread :: Next Thread 
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
09 Feb 2015 05:37 PM
I tried making the movement less choppy by putting a while loop. How would I make it if let's say I wen't right, it wouldn't let me go left until I stopped going right?

Code:

local Player = game.Players.LocalPlayer
local GuiPlayer = script.Parent
local Mouse = Player:GetMouse()

function moveRight(Key)
if Key == "d" then
print("Moving right")
while wait() do
GuiPlayer.Position = GuiPlayer.Position +UDim2.new(0.01, 0, 0, 0)
end
end
end

function moveLeft(Key)
if Key == "a" then
print("Moving left")
while wait() do
GuiPlayer.Position = GuiPlayer.Position -UDim2.new(0.01, 0, 0, 0)
end
end
end

function moveUp(Key)
if Key == "w" then
print("Moving up")
end
end

function moveDown(Key)
if Key == "s" then
print("Moving down")
end
end

function Jump(Key)
if Key:byte() == 32 then
print("Jumping")
end
end

Mouse.KeyDown:connect(moveRight)
Mouse.KeyDown:connect(moveLeft)
Mouse.KeyDown:connect(moveUp)
Mouse.KeyDown:connect(moveDown)
Mouse.KeyUp:connect(Jump)

"I like to program." - Bosswalrus
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
09 Feb 2015 05:44 PM
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Keys = {
w = false; a = false; s = false; d = false; e = false; q = false;
}

local Invert = function(key)
Keys[key] = not Keys[key]
end

Mouse.KeyDown:connect(Invert)
Mouse.KeyUp:connect(Invert)

while true do
Player.Character.Torso.CFrame = Character.Torso.CFrame * CFrame.new(
a and -1 or d and 1, e and 1 or q and -1, a and -1 or d and 1
)
wait(0)
end
-- TODO: Use renderstepped
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
09 Feb 2015 05:52 PM
local player = game.Players.LocalPlayer;
local guiPlayer = script.Parent;

local mouse = player:GetMouse();
local MOVE_SPEED = 0.01;

local keys = {
UP = false;
LEFT = false;
RIGHT = false;
DOWN = false;
};



local updateKey = function (key, pressed)
if (key == "w") then
keys.UP = pressed;
elseif (key == "a") then
keys.LEFT = pressed;
elseif (key == "d") then
keys.RIGHT = pressed;
elseif (key == "s") then
keys.DOWN = pressed;
end
end;



local onKeyDown = function (key)
updateKey(key, true);
end;



local onKeyUp = function (key)
updateKey(key, false);
end;



local movePlayer = function (player, moveVec)
player.Position = player.Position + moveVec;
end;



local handleInput = function (deltaTime)
local dx = 0;
local dy = 0;

if (keys.UP) then
dy = dy - 1;
end
if (keys.DOWN) then
dy = dy + 1;
end

if (keys.LEFT) then
dx = dx - 1;
end
if (keys.RIGHT) then
dx = dx + 1;
end

local dd = dx*dx + dy*dy;
if (dd > 0) then
-- Not sure on this bit
dd = math.sqrt(dd);

dx = dx / dd;
dy = dy / dd;
end


local moveX = dx * deltaTime * MOVE_SPEED;
local moveY = dy * deltaTime * MOVE_SPEED;

local moveVec = UDim2.new(moveX, 0, moveY, 0);

movePlayer(guiPlayer, moveVec);
end;



local update = function (deltaTime)
handleInput(deltaTime);
end;



local main = function ()
while (true) do
local deltaTime = wait(); -- I think this is correct
update(deltaTime);
end;
end;



mouse.KeyDown:connect(onKeyDown);
main();
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
09 Feb 2015 05:53 PM
Tween it thar
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
09 Feb 2015 06:02 PM
What a big script for no reason ._.
Report Abuse
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
09 Feb 2015 08:48 PM
Wouldn't tweening it make it go choppy. Also that code is giant, I'll try and research it tomorrow.

"I like to program." - Bosswalrus
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
10 Feb 2015 04:13 PM
i prefer to do deltaTime like this:

local dt, lastStep;

game:GetService("RunService").RenderStepped:connect(function()
dt = lastStep and tick() - lastStep or 1 / 30 --1 / 30 is a good estimation for when lastStep doesn't yet exist
lastStep = tick()

end)
Report Abuse
drager980 is online. drager980
Joined: 25 May 2009
Total Posts: 13385
10 Feb 2015 04:14 PM
@FD, arent you like
a day late
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
10 Feb 2015 04:20 PM
pfft no
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