Code archives/3D Graphics - Maths/YawToEntity function (plus smart missile code).

This code has been declared by its author to be Public Domain code.

Download source code

YawToEntity function (plus smart missile code). by Zethrax2008
The YawToEntity function turns the specified source entity to point at the specified target entity at the rate specified. Turning is performed on the Y (yaw) axis. The rate value is applied each time the function is called, so the rate of change will depend on how frequently the function is called.

In addition to the 2D-in-3D homing missile code used as an example below, the function could also be used to turn a bot to face a waypoint, or some other objective.

---

Here's the code for the YawToEntity function. It includes example code showing a smart missile homing in on a target.

Note that, a problem that I encountered with homing missiles, is that they can easily get locked into an orbit around the object they are targetting - particularly if that object is stationary. The smart missile code below deals with that by preventing the missile from turning if the missile is within a certain distance, and angle, relative to the target. The missile is prevented from turning until it has reached a certain distance from the target. The version of the code intended for ground based combat will allow the missile to turn, until it is pointing upwards, to reduce the chance that it will impact against a ground plane.

This code is for a space based game, where there's no ground plane for the missile to worry about.



This code is for a ground based game, where there's a ground plane for the missile to worry about.
No code here, sorry. I prefer using a codebox.

Code is at: http://www.blitzbasic.com/codearcs/codearcs.php?code=2258

Comments

Nate the Great2008
Cool!

I added an avoid entity function in the code archives!


Code Archives Forum