IGNORED

# Fire at a target without using divide? How did Missile Command do it?

## Recommended Posts

Hello!

I'm trying to make a projectile fire at a x / y location on the screen. Obviously, this is easy with a modern system and I'd normally use (pseudo code):

```ProjectileVector = OriginXY - TargetXY
ProjectileVector.Normalize
MissileSpeed = ProjectileVector * MaximumSpeed
```

Normalizing the vector allows you to multiply it by your maximum missile speed and get set the proper X / Y velocity to strike the target.

What I'm doing now is:

``` target_distance_x = (player3x - target_x)  / 4
target_distance_y = (player3y - target_y)  / 4
```

I'm using / 4 to get the projectile to follow a path based on my playfield resolution. player3 is my missile sprite. (Using DPC+)

This leaves me with, for example, target_distance_x = 5, target_distance_y = 3

Which is correct, but I can't just make those numbers my missile velocity because they're way too fast.

I don't how if it's possible to normalize target x and y (would need fixed point numbers and division) and if it is, you'd still need to multiply those by another number to get the right velocity.

If I divide the target_distance by 2 or 4 or whatever, the missile goes slower, but not to the right location. Rounding errors.

How did Missile Command aim missiles?

##### Share on other sites

Ah, what a great resource!

That is some serious code voodoo. I've got it working now but I don't really understand it. Not that I'm complaining!

I use your website all time trying to learn my way around the Atari. Thanks for creating it!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.