BodyPosition take a strange path

Hello !

  1. What do you want to achieve?

I’m making a projectile go to a part as soon at it is fired

  1. What is the issue?

The issue is that it’s always doing some strange curve and never goes straight to the goal part

  1. What solutions have you tried so far?

I looked but I couldn’t find a solution for this because I don’t know why it’s doing that, maybe using BodyPosition wasn’t the good choice or maybe I should change the properties

local tempPos = rooms[math.random(1,#rooms)].Position
local pos = Vector3.new(tempPos.x + math.random(-10,10) , tempPos.y + math.random(-5,5) , tempPos.z + math.random(-10,10) )
b.position = pos
b.D = 0
b.P = 10000
b.maxForce = Vector3.new(10, 5, 10)
b.Parent = laser

I put the D at 0 because if it miss it miss I thought. For the P and maxForce I never know what to put, I randomly put ones until it seems good but here I can’t make it work.

I made a “drawing” to show the problem. I think it’s because it try to go to the nearest point it can. The red cube is the goal part. It is in a box and the ball is the projectile that have the bodyforce. I want it to do what the red arrow does but it does the black arrow in the game.
why

I would try calculating the mass of the part and adding a body force to counteract gravity. You can calculate the force needed by mass*workspace gravity.
(If the strange curve is like a parabola then this is probably the answer, I haven’t needed to use body positions yet so I am not entirely sure.)

I forgot to mention but I already have a antiGravity bodyforce with this script :

local function setGravity(part)
	local antiGravity = part:FindFirstChild("AntiGravity")
	if not antiGravity then
		antiGravity = Instance.new("BodyForce")
		antiGravity.Name = "AntiGravity"
		antiGravity.Archivable = false
		antiGravity.Parent = part
	end
	antiGravity.Force = Vector3.new(0, part:GetMass() * workspace.Gravity * 1, 0)
end 

That’s why I really don’t understand the problem. I think the problem is that bodyForce search for the nearest part in case it can’t touch it. What I mean is that my goal part is in a box and I think the bodyforce try to go to the nearest point it can in case it can’t go to it’s goal.

Something that might be important to note, the vector maxforce represents the max force for each axis. It looks like it also might be over correcting on the x axis. Maybe increase D a bit? 0 is a bit low.