So I have a lock on system in my game, when I’m not locked onto a humanoid, the velocity works fine, it goes wherever I’m facing, I set my velocity to this:
Instead of setting it to the lookVector of the player’s Character, why not align the projectile directly to the target? If it’s locked on, then won’t the target always be the center of the screen?
local vec = CFrame.new(projectile.Position, target.Position).lookVector
projectile.Velocity = vec*speed
unfortunately still doesnt work, unless im being dummy and i messed it up
local vel = Instance.new('BodyVelocity',sslash)
vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
if p.Backpack.LockON.Target.Value ~= nil then
local vec = CFrame.new(sslash.Position, workspace:FindFirstChild(p.Backpack.LockON.Target.Value.Name).Torso.Position).lookVector
vel.Velocity = vec*200
elseif p.Backpack.LockON.Target.Value == nil then
vel.Velocity = hrp.CFrame.LookVector*200
end
The only other suggestion I can offer is using CFrame:lerp() to make sure it does go directly to the target position.
--define your variables here
local projectile
local target
local hasTouched = false
projectile.Touched:connect(function(hit)
hasTouched = true
end)
local scale = 0
local speed = 200 -- Studs per second
local refreshSpeed = 0.1 --* 1 second
local spin = 0
local spinSpeed = 90 -- degrees per second
local startCF = projectile.CFrame
local distance = (target.Position - projectile.Position).Magnitude
projectile.CFrame = CFrame.new(projectile.Position, target.Position) -- update rotation to face the target
while scale < 1 and hasTouched == false do
projectile.Anchored = true
scale = scale + ((1/distance)*speed)*refreshSpeed -- Calculate the rate of change, multiply by refresh rate
spin = spin + (spinSpeed*refreshRate) -- increase rotation
projectile.CFrame = startCF:Lerp(target.CFrame, scale)-- move closer to the target
projectile.Orientation = projectile.Orientation - Vector3.new(projectile.Orientation.X, 0, 0) -- return orientation on X Axis to 0
projetile.CFrame = projectile.CFrame * CFrame.Angles(math.rad(spin),0,0) -- rotate X axis accordingly
wait(refreshSpeed)
end
projectile.Touched:Disconnect()
This might not be the effect you’re going for though so imma leave it up to you.