- Home /
Guided Missile
Missile in my game is not acting as i expect.
See attached image of the trajectory of my missile. Start point is upper right corner of the image. Missile is guided to target by AddTorque. Target is the large grey cube. As the missile is fired to a stationary target--head-on, i would expect the missile to be guided directly to the target-not narrowly missing the target.
Attempting to simulate Aim-9 sidewinder missile
(quick specs) weight: 85kg thrust: ~19 kN (classified, estimated value, older versions ~17 kN) max speed: mach 2.5 (680.58 m/s)
The physics in my game are the following:
Missile is a Rigidbody Mass 85 Drag 0.25 Angular Drag 20 Use Gravity yes Kinematic no
Controlling Script below
Start()
{
//Fired from moving jet.
rigidbody.isKinematic = false;
rigidbody.velocity = this.parentRB.velocity;
//19000 is 19 kN of estimated thrust form Aim-9 missile
constantForce.relativeForce = Vector3.forward * 19000;
}
FixedUpdate()
{
var x : Transform;
x = transform;
x.LookAt(target.transform);
rigidbody.AddTorque(x.position * 0.1);
}
Any advice on how to better simulate the missile would be appreciated. Thanks
I havent tested your code, but as far as I understand physics, you need to do those calculations in the FixedUpdate. Secondly, why do you use the X position of a missile moving forward? Z is forward.
AddTorque spins you, so I'm guessing its job is to turn the missle towards the target. BUT, the line x.LookAt(target.transform)
snaps the missile directly there.
Also, AddTorque takes an axis as input, not a position. If you fire a missile facing +z while at the far-right bottom of the map, say (1000,0,0) your AddTorque command tells the missle to tumble over the x-axis, doing crazy loops.
I'm guessing the "real world" solution is to get rid of LookAt and figure how to AddTorque over the proper angle (but then you'll have problems with oversteering -- I'm guessing real missiles had the same problem and the guidance chips are doing lots of math, today.)
BerggreenD$$anonymous$$: He isn't really using the X-position. He's using the "look up the transform first" trick. It's rumored that writing transform
is really doing a search through your components to find your transform. If you write x=transform;
and then use x.this and x.that, you only do that time-wasting search once.
So, x.position
on the last line is really transform.position
. But, yeah, I'd have gone with T ins$$anonymous$$d of x.