# How to check if rocket is pointed near to target position

I’m trying to make a rocket using vector force and i dont know how to check when rocket is pointed near to target position. How to do this?

You can check for the rocket’s CFrame.LookVector + CFrame.Position, which is 1 stud in the direction it’s facing. You can multiply the lookvector by the distance the rocket is from the target point before adding to get the exact position. I’m not sure but there’s probably a more complicated math solution as well.

This is what I’d do:

``````local direction = rocket.CFrame.LookAt
local dist = (targetPoint - rocket.Position).Magnitude

-- you might want to do within a certain distance in case it's off due to a floating point error.
if direction * dist + rocket.Position == targetPoint then
return true
end
``````

edit: I see you said near, so editing this script:

``````local direction = rocket.CFrame.LookAt
local dist = (targetPoint - rocket.Position).Magnitude
local maxDistance = 5 -- within 5 studs marks it as true

-- you might want to do within a certain distance in case it's off due to a floating point error.
local possibleTarget = direction * dist + rocket.Position
if (possibleTarget - targetPoint).Magnitude <= maxDistance then
return true
end
``````

It doesnt see the target
I did as you’d do and changed it a little bit

``````local direction = script.Parent.Parent.lookin.CFrame.LookVector
local dist = (workspace.aimingobj.Position - script.Parent.Parent.lookin.Position).Magnitude
local maxDistance = 100 -- within 5 studs marks it as true
local rocketisaimed = false
-- you might want to do within a certain distance in case it's off due to a floating point error.
local possibleTarget = direction * dist + script.Parent.Parent.lookin.Position
repeat wait()
if (possibleTarget - workspace.aimingobj.Position).Magnitude <= maxDistance then
rocketisaimed = true
end
until rocketisaimed == true
``````
1 Like