Hey so I'm making a basketball game, I wan't to make it so that when A player presses a key, it will perform the animation and move the player to either the left or right.
However the way I done it, when a player rotates and presses the key, they can get moved forward and backwards instead of right and left.
Key Press
UIS.InputBegan:Connect(function(key , gpe)
if key.KeyCode == KeyBindingModule:SwitchHands() and not gpe then
if animations.right_dribble.IsPlaying then
animations.right_dribble:Stop()
animations.switch_left:Play()
createVelocity(0,0,15)
animations.switch_left:Stop()
animations.left_dribble:Play()
elseif animations.left_dribble.IsPlaying then
animations.left_dribble:Stop()
animations.switch_right:Play()
createVelocity(0,0,-15)
animations.switch_right:Stop()
animations.right_dribble:Play()
end
end
end)
Velocity Function
local function createVelocity(x , y, z)
local newVelocity = Velocity:Clone()
newVelocity.Velocity = Vector3.new(x,y,z)
newVelocity.Parent = Character.Torso
wait(.25)
newVelocity:Destroy()
end

1 comment
Take the cross product between the character's HumanoidRootPart's look vector and the y-axis. See here: https://scriptinghelpers.org/questions/61374/#59749