missile hitting the shooter?

BlitzMax Forums/BlitzMax Beginners Area/missile hitting the shooter?

Drakim(Posted 2008) [#1]
I have a pretty basic problem here, and I'm wondering if there is any more effective and painless method of fixing it.

I have a problem of units shooting and hitting themselves, right when the missile is created.

This could easily be solved by storing who is the shooter in a field in the missle, and not have the missile collide with the shooter.

However, I have a system with magnets and stuff where the shot can be flung back at you. Having the shooter not being able to shoot himself fails then.

A second possibility would be to have a delay on the missile until it starts colliding with objects. However, this caused other troubles. When I had a very slow and big missile, the delay wasn't enough, and the unit collided with his own missile anyway. I fixed this by making the delay longer. However, when the unit shot a missile really fast, enemies that are too close was also skipped due to the now longer delay.

So, what other tricks can one use to avoid this simple yet troublesome problem?


tonyg(Posted 2008) [#2]
Don't let a missile hit it's owner until it has been affected by a magnet?


GfK(Posted 2008) [#3]
Slightly generic answer since you haven't said if you're using 2D or 3D:

The easiest solution would be to think about how missiles work in the real world. I.e. if you shoot a rocket launcher at your own head, its probably going to kill you. The simplest answer is to create the missile slightly in front of the player, so that it never touches him (unless its been forced back at him by magnets or whatever).

Alternatively, when you detect a collision between missile and player, you could use Atan2() to determine whether the missile is moving towards or away from whatever its detected a collision with.


Perturbatio(Posted 2008) [#4]
you could just ignore all collisions with the missile until it hasn't collided with it. (if that makes sense)


GfK(Posted 2008) [#5]
you could just ignore all collisions with the missile until it hasn't collided with it. (if that makes sense)
You mean, wait until there's been at least one non-collision before it actually acts on a collision?

Problem with that is if the enemy is right in front of you. It could theoretically pass right through the enemy without registering a hit.


QuietBloke(Posted 2008) [#6]
You could have the missile store who fired it and have a flag ( eg LaunchingFlag ) which is initially set to true.
Then you can apply the following logic.

If the LaunchingFlag is true and it is not colliding with whoever fired it then set the flag to false.

If a collision is detected against whoever fired it and the LaunchingFlag is true then ignore the collision.

All other collisions are valid.

or something like that.

Cheers


Czar Flavius(Posted 2008) [#7]
In other words, the missile remembers who fired it, until it is no longer colliding with him, then it forgets and can hit.

The atan2 suggestion sounds clever.


QuietBloke(Posted 2008) [#8]
yeah.. sorry.. that's a much quicker way of putting it.. My brain went into waffle mode !


Drakim(Posted 2008) [#9]
Yeah, it's 2D.

I'll try the atan2 suggestion first. It creates the most realistic results. ^^

Thanks for all the suggestions though!