Hello, I've been trying to script a ball that flies after the player clicks it. I've tried a script where the ball actually does leave the hand, but it doesn't go
This was the script I had:
local ball = script.Parent.Handle local tool = script.Parent local character = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded:wait() tool.Equipped:connect(function(Mouse) Mouse.Button1Down:connect(function() local b = ball:Clone() b.Parent = game.Workspace local P = Instance.new("BodyPosition", b) P.Position = character.Head.Position + Vector3.new(0, 0, 0.5) local V = Instance.new("BodyVelocity", b) V.Velocity = Vector3.new(1, 0, 0) wait(.1) tool.Parent = game.ServerStorage end) end)
In this script, the ball did fly through the air. However, I want to change it so that instead of the ball having to follow the axes, and it always go in the same direction, it will always move directly in front of the player. (I don't have very much experience with this type of scripting)
How could I change
V.Velocity = Vector3.new(1, 0, 0)
so that the ball always in what the player sees as in front of them?
Typically for velocity you want to supply a direction. All vectors have a direction, but it is made more clear with the unit vector, because everything is in ratio 0-1. CFrames are composed of these unit vectors. The CFrame lookVector is the axis a BasePart is looking. Supply the head's direction like so:
V.Velocity = character.Head.CFrame.lookVector
You can multiply this by any number to resize the vector. For example:
V.Velocity = character.Head.CFrame.lookVector * 5
BTW it seems weird to have BodyPosition and BodyVelocity at the same time. Bodyp is meant to keep a part in one place. This is all up to you though!