So I recently posted about a fly script, and had someone in Discord help me with it, but I have one problem, I want the animation to follow your mouse. Basically, what happens is whichever direction you move to with ‘WASD’ changes the animation to face that way, but I want it to face the direction I point my mouse. Could anyone help me with this? All help is appreciated!
local id = (AnimID)
repeat wait() until (game.Players.LocalPlayer.Character:WaitForChild("Humanoid") ~= nil)
local animObj = Instance.new("Animation")
animObj.AnimationId = "rbxassetid://" .. id
local anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animObj)
anim.Looped = true
local player = game.Players.LocalPlayer --Refer the player
local mouse = player:GetMouse() --Lets get the players mouse so we can get the flying direction
local character = player.Character or player.CharacterAdded:Wait() --Lets wait for the character to be added
local BV = Instance.new("BodyVelocity",character:WaitForChild("HumanoidRootPart")) --Lets create BodyVelocity and parent it to the HumanoidRootPart of our player
local speed = 100
local Bind = false
local UIS = game:GetService("UserInputService")
BV.MaxForce = Vector3.new()
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F and not Bind then
Bind = true
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
anim:Play()
elseif input.KeyCode == Enum.KeyCode.F and Bind then
Bind = false
BV.MaxForce = Vector3.new()
anim:Stop()
end
end)
UIS.InputChanged:Connect(function() --Detect when the mouse moves
BV.Velocity = CFrame.new(character.HumanoidRootPart.Position,mouse.Hit.Position).LookVector * speed --Set Velocity to the mouse position everytime the mouse moves
end)```
Edit: Fixed video.