Position-guided Missile Always Misses Target

TL:DR; I’ve struggled in trying to adjust an AlignOrientation’s LookAtPosition based on the missile’s velocity to limit misses due to momentum and I need help.

It’s my first time attempting to build a missile on my own and I ran into a wall. I want to figure out how I can make my missile (that is powered by an AlignOrientation and a LinearVelocity) stop over/undershooting it’s target.

The Setup I’m Using
With the current missile setup, there are attachments in 3 positions of the missile: front, back, and centre. The AlignOrientation and LinearVelocity act on the front and back attachments respectively. The issue with my setup is the missile will point directly at the target, which doesn’t work when the missile’s momentum is moving away from the target. There is a VectorForce that counter’s the missiles gravity which I don’t think is relevant enough to factor into this topic.

What I’ve Done
I have played around with various settings on both the AlignOrientation and the LinearVelocity and the problem still persists. I have tried thinking of my own formulas, which never worked. I tried to search for other forum topics with all the keywords I could think of but found nothing relevant as everyone else seems to be using CFrame to adjust their missile positions.

Properties
If I’m missing something in terms of properties, here is the code that creates both movers:

local alignOrientation = Instance.new("AlignOrientation", missile)
alignOrientation.Name = "MissileLookAt"
alignOrientation.Responsiveness = 10000
alignOrientation.MaxAngularVelocity = math.huge
alignOrientation.RigidityEnabled = false -- doesn't make a difference in accuracy
alignOrientation.Attachment0 = frontSideAttachment
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
alignOrientation.AlignType = Enum.AlignType.PrimaryAxisLookAt
alignOrientation.LookAtPosition = targetPosition

local rocketVelocity = Instance.new("LinearVelocity", missile)
rocketVelocity.Name = "RocketVelocity"
rocketVelocity.Attachment0 = backSideAttachment
rocketVelocity.MaxForce = 625 * missile.AssemblyMass * targetVelocity^2
rocketVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
rocketVelocity.LineVelocity = targetVelocity
rocketVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0

The LookAtPosition is a simple heartbeat loop that updates the LookAtPosition to the target position (supports vector3, parts and models)

A solution that I imagine working in my head would be some way to adjust the LookAtPosition based off one or more of the following:

  • The velocity of the missile
  • The orientation of the missile relative to the target position

Reference Media
Here you can see the missile fail miserably at the one job it was tasked to do (and my failure to have that job completed)

Missile Fail 4

(I’m fairly new to DevForum, just got my account back up after clearing up email issues.)

1 Like