Custom Client-Side Movement Keys No Ifs

local _mover = World.FindObjectByName("bwob2")
local _movec = World.FindObjectByName("bcam2")
local _midpoint = World.FindObjectByName("midpoint")
print(_movec:GetPosition())

local _mVector = _mover:GetPosition()
local _speed = 33
local _fspeed = 0
local _rspeed = 0
local _uspeed = 0
local _keyMode = ""


function _moveIt()
    _mVector.x = _mVector.x + _fspeed
    _mVector.y = _mVector.y + _rspeed
    _mVector.z = _mVector.z + _uspeed
    _mover:SetPosition(_mVector)
    --_movec:SetPosition(_mVector - (Vector3.FORWARD * 30) + (Vector3.UP * 200))
end

-- PRESSED KEYS
_G["ability_extra_21"] = function()
    _keyMode = "FORWARD"
    _fspeed = _speed
end
_G["ability_extra_30"] = function()
    _keyMode = "LEFT"
    _rspeed = -_speed
end
_G["ability_extra_31"] = function()
    _keyMode = "BACK"
    _fspeed = -_speed
end
_G["ability_extra_32"] = function()
    _keyMode = "RIGHT"
    _rspeed =  _speed
end
_G["ability_extra_46"] = function()
    _keyMode = "UP"
    _uspeed = _speed
end
_G["ability_extra_47"] = function()
    _keyMode = "DOWN"
    _uspeed = -_speed
end
_G["ability_secondary"] = function()
    UI.PrintToScreen("RMouse")
end

-- RELEASED KEYS
_G["release_ability_extra_21"] = function()
    _fspeed = 0
end
_G["release_ability_extra_30"] = function()
    _rspeed = 0
end
_G["release_ability_extra_31"] = function()
    _fspeed = 0
end
_G["release_ability_extra_32"] = function()
    _rspeed =  0
end
_G["release_ability_extra_46"] = function()
    _uspeed = 0
end
_G["release_ability_extra_47"] = function()
    _uspeed = 0
end

function OnBindingPressed(player, binding) -- keys are being pressed!
    --assert(binding == "ability_secondary" or binding == "ability_extra_47", "This binding is not used.")
    --return _G[binding]()
    if pcall(_G[binding]) then end-- suppress errors for non-set keys -> functions
end

function OnBindingReleased(player, binding)
    --assert(binding == "ability_secondary" or binding == "ability_extra_47", "This binding is not used.")
    --return _G[binding]()
    if pcall(_G["release_"..binding]) then end-- suppress errors for non-set keys -> functions
end

Game.playerJoinedEvent:Connect(function(player)
    player.bindingPressedEvent:Connect(OnBindingPressed)
    player.bindingReleasedEvent:Connect(OnBindingReleased) 
end)



function _switchMode(dir)
  _keyMode = dir
end

function Tick()
    _moveIt()
    _movec:SetRotationOffset(_midpoint:GetRotation())
end

function _onEnterFrame()
    _midpoint:LookAt(_mover:GetPosition())
    --_movec:RotateTo(Rotation.New(_midpoint:GetRotation()), 1.8)
    
end

local _task = Task.Spawn(function() _onEnterFrame() end)
_task.repeatCount = -1
_task.repeatInterval = .1


_midpoint:Follow(_movec,2500,0)
_movec:Follow(_mover, 1000, 1600)

Latest Posts