So I made a movement system that has a custom StarterCharacter move along a grid space. Aside from some small rotation issues, the main thing now is that I want the player’ character model to “hop” along as it moves across the grid space and I don’t really know how to go about doing that. I tried with tweens and got nothing working (probably by doing something wrong idk).
Here is the entire movement code that I have in a LocalScript that is in StarterCharacterScripts.
local userInputService = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local player = script.Parent:WaitForChild("actualCharacter")
local p1 = script.Parent:WaitForChild("Head")
local p2 = script.Parent:WaitForChild("Torso")
local humanoid = script.Parent:WaitForChild("Humanoid")
local mouse = game.Players.LocalPlayer:GetMouse()
game:GetService("RunService").Heartbeat:Connect(function()
p1.Orientation = player.Orientation
p2.Orientation = player.Orientation
end)
task.delay(1, function()
player.Orientation = Vector3.new(0, 0, 0)
p1.Orientation = Vector3.new(0, 0, 0)
p2.Orientation = Vector3.new(0, 0, 0)
end)
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
local distance = 8
local moveTime = .18
local rotateTime = .3
local moveTweenInfo = TweenInfo.new(moveTime, Enum.EasingStyle.Quart)
local rotateTweenInfo = TweenInfo.new(rotateTime, Enum.EasingStyle.Quart)
local squishTime = .4
local squishTweenInfo = TweenInfo.new(squishTime, Enum.EasingStyle.Quart)
local tweenEnabled = false
local facingDirectionFB
local facingDirectionLR
--squish start variables
local tweenStart = tweenService:Create(player, squishTweenInfo, {Size = Vector3.new(player.Size.X + .5, player.Size.Y - 3, player.Size.Z)})
local tweenStart2 = tweenService:Create(p1, squishTweenInfo, {Size = Vector3.new(p1.Size.X + .5, p1.Size.Y - 3, p1.Size.Z)})
local tweenStart3 = tweenService:Create(p2, squishTweenInfo, {Size = Vector3.new(p2.Size.X + .5, p2.Size.Y - 3, p2.Size.Z)})
--squish end variables
local tweenEnd = tweenService:Create(player, squishTweenInfo, {Size = Vector3.new(player.Size.X, 10.55, player.Size.Z)})
local tweenEnd2 = tweenService:Create(p1, squishTweenInfo, {Size = Vector3.new(p1.Size.X, 10.55, p1.Size.Z)})
local tweenEnd3 = tweenService:Create(p2, squishTweenInfo, {Size = Vector3.new(p2.Size.X, 10.55, p2.Size.Z)})
--player noises when moving
local sounds = {}
for i, child in pairs(game.SoundService.playerSounds.chicken:GetChildren()) do
if child:IsA("Sound") then
table.insert(sounds, child)
end
end
--commences the squishing
userInputService.InputBegan:Connect(function(input, Processed)
if not Processed then
if tweenEnabled == true then return end
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.Up then
tweenStart:Play()
tweenStart2:Play()
tweenStart3:Play()
elseif input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.Down then
tweenStart:Play()
tweenStart2:Play()
tweenStart3:Play()
elseif input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.Left then
tweenStart:Play()
tweenStart2:Play()
tweenStart3:Play()
elseif input.KeyCode == Enum.KeyCode.D or input.KeyCode == Enum.KeyCode.Right then
tweenStart:Play()
tweenStart2:Play()
tweenStart3:Play()
end
end
end)
--releases the squishing and does movement
userInputService.InputEnded:Connect(function(input, Processed)
if not Processed then
if tweenEnabled == true then return end
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.Up then
facingDirectionFB = 1
tweenEnabled = true
tweenEnd:Play()
tweenEnd2:Play()
tweenEnd3:Play()
sounds[math.random(1, #sounds)]:Play()
frontMove()
elseif input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.Down then
facingDirectionFB = -1
tweenEnabled = true
tweenEnd:Play()
tweenEnd2:Play()
tweenEnd3:Play()
sounds[math.random(1, #sounds)]:Play()
backMove()
elseif input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.Left then
facingDirectionLR = 1
tweenEnabled = true
tweenEnd:Play()
tweenEnd2:Play()
tweenEnd3:Play()
sounds[math.random(1, #sounds)]:Play()
leftMove()
elseif input.KeyCode == Enum.KeyCode.D or input.KeyCode == Enum.KeyCode.Right then
facingDirectionLR = -1
tweenEnabled = true
tweenEnd:Play()
tweenEnd2:Play()
tweenEnd3:Play()
sounds[math.random(1, #sounds)]:Play()
rightMove()
end
end
end)
--commences the squishing for mouse
mouse.Button1Down:Connect(function()
if tweenEnabled == true then return end
tweenStart:Play()
tweenStart2:Play()
tweenStart3:Play()
end)
--releases the squishing and does movement for mouse
mouse.Button1Up:Connect(function()
if tweenEnabled == true then return end
tweenEnabled = true
facingDirectionFB = 1
tweenEnd:Play()
tweenEnd2:Play()
tweenEnd3:Play()
sounds[math.random(1, #sounds)]:Play()
frontMove()
end)
--movement stuffs
function frontMove()
local tween = tweenService:Create(player, moveTweenInfo, {Position = player.Position + Vector3.new(0, 0, -distance)})
local tween2 = tweenService:Create(p1, moveTweenInfo, {Position = p1.Position + Vector3.new(0, 0, -distance)})
local tween3 = tweenService:Create(p2, moveTweenInfo, {Position = p2.Position + Vector3.new(0, 0, -distance)})
local rotateTween = tweenService:Create(player, rotateTweenInfo, {Orientation = Vector3.new(0, 0, 0)})
if (player.Orientation.Y > 1 or player.Orientation.Y < -1) and facingDirectionFB == 1 then
rotateTween:Play()
end
tween:Play()
tween2:Play()
tween3:Play()
task.wait(moveTime)
facingDirectionFB = nil
tweenEnabled = false
end
function backMove()
local tween = tweenService:Create(player, moveTweenInfo, {Position = player.Position + Vector3.new(0, 0, distance)})
local tween2 = tweenService:Create(p1, moveTweenInfo, {Position = p1.Position + Vector3.new(0, 0, distance)})
local tween3 = tweenService:Create(p2, moveTweenInfo, {Position = p2.Position + Vector3.new(0, 0, distance)})
local rotateTween = tweenService:Create(player, rotateTweenInfo, {Orientation = Vector3.new(0, -180, 0)})
if (player.Orientation.Y > 181 or player.Orientation.Y < 179) and facingDirectionFB == -1 then
rotateTween:Play()
end
tween:Play()
tween2:Play()
tween3:Play()
task.wait(moveTime)
facingDirectionFB = nil
tweenEnabled = false
end
function leftMove()
local tween = tweenService:Create(player, moveTweenInfo, {Position = player.Position + Vector3.new(-distance, 0, 0)})
local tween2 = tweenService:Create(p1, moveTweenInfo, {Position = p1.Position + Vector3.new(-distance, 0, 0)})
local tween3 = tweenService:Create(p2, moveTweenInfo, {Position = p2.Position + Vector3.new(-distance, 0, 0)})
local rotateTween = tweenService:Create(player, rotateTweenInfo, {Orientation = Vector3.new(0, 90, 0)})
if (player.Orientation.Y > 89 or player.Orientation.Y < -89) or (player.Orientation.Y > -1 or player.Orientation.Y < 1) and facingDirectionLR == 1 then
rotateTween:Play()
end
tween:Play()
tween2:Play()
tween3:Play()
task.wait(moveTime)
facingDirectionLR = nil
tweenEnabled = false
end
function rightMove()
local tween = tweenService:Create(player, moveTweenInfo, {Position = player.Position + Vector3.new(distance, 0, 0)})
local tween2 = tweenService:Create(p1, moveTweenInfo, {Position = p1.Position + Vector3.new(distance, 0, 0)})
local tween3 = tweenService:Create(p2, moveTweenInfo, {Position = p2.Position + Vector3.new(distance, 0, 0)})
local rotateTween = tweenService:Create(player, rotateTweenInfo, {Orientation = Vector3.new(0, -90, 0)})
if (player.Orientation.Y > -89 or player.Orientation.Y < 89) and facingDirectionLR == -1 then
rotateTween:Play()
end
tween:Play()
tween2:Play()
tween3:Play()
task.wait(moveTime)
facingDirectionLR = nil
tweenEnabled = false
end
--enable for view of player grid space
--[[
local part = Instance.new("Part")
part.Size = Vector3.new(8, 10.5, 8)
part.Anchored = false
part.CanCollide = false
part.Transparency = .7
part.Parent = player.Parent
local weld = Instance.new("WeldConstraint")
weld.Part0 = player.Parent:WaitForChild("Part")
weld.Part1 = player
weld.Parent = part
game:GetService("RunService").Heartbeat:Connect(function()
part.Position = player.Position
end)
]]
And here is the .rbxl file with everything along with the crudely made StarterCharacter.
(You’ll probably notice where i’m going with this project).
example.rbxl (55.9 KB)