Bodyvelocity does not move part towards boss

hi guys the title explains it all but heres the code i got

				local newVelocity = Instance.new("BodyVelocity")
				newVelocity.MaxForce = Vector3.new(4000, 4000, 4000)
				newVelocity.P = 1250;
				newVelocity.Parent = projectileAttackSphere;
				local endGoal = (boss.HumanoidRootPart.Position - projectileAttackSphere.Position).Unit;
				newVelocity.Velocity = endGoal * 80

basically when i move around the boss for some reason the orb moves in a different direction instead of towards the boss.

i looked for solutions everywhere and i cant find any that help my problem
thank you

couldn’t you just

newVelocity.Velocity = -endGoal * -80

this solves one axis but ive been picking my brain out to try and redirect the part towards the boss on the other axis (this happens when im moving around the boss and not right infront of it)

Try using Torso or UpperTorso instead of HumanoidRootPart since it’s supposed to be a damaging object or whatever.

Hello! This confused me too, and I did a little digging and found that BodyVelocity is deprecated, so maybe that is why it acts a little funky?

I ended up finding a solution with code similar to yours using LinearVelocity, which is the reccomended replacement for it.

--LinearVelocity requires an attachment, so create one and parent it to the projectile
local attachment = Instance.new("Attachment", projectileAttackSphere)

local newVelocity = Instance.new("LinearVelocity")
newVelocity.MaxForce = 4000
newVelocity.Parent = projectileAttackSphere;
newVelocity.Attachment0 = a0
local direction = (boss.HumanoidRootPart.Position - projectileAttackSphere.Position).Unit
newVelocity.VectorVelocity = direction * 80

Hope this helps! The code should be decently self-explanatory, the Velocity property is just named VectorVelocity instead!

1 Like

This works exactly like i wanted it too thank you! another question when it reaches the designated goal how can i detect that? Thanks again for the solution you are a life saver!

You could use a magnitude check:

-- The distance between the points
(boss.HumanoidRootPart.Position - projectileAttackSphere.Position).Magnitude 

Just check the magnitude while the projectile is in the air, magnitude checks like this are very performant. AFAIK the .Touched event is not recommended, so while that is also an option, magnitude checks are probably better if you plan to have many projectiles like this!

Thank you so much for this solution! It works brilliantly! Have a good rest of your day!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.