Moving through moving objects


for learning purpuse, I set myselfa target to make a little Star Shooter.

Right now you can move the ship, asteroids are spawning and enemys are moving down to your space ship, shooting, in a sine wave (math calculated no matinee).

What I try to do is, that the enemy space ships avoid the astroids while flying down. It would be easy to make wave after wave or let them crush into the astroids but I want them to behave a little smarter.

Does anybody have an idee how to do this?

My First thought was a navmesh (never used it) but all I read about it, its not very good to use it if you need a frame by frame update.

Can I get the angle of between two moving objects to adjust the math path the enemy is moving (to avoid collision with the astroids)? Both have a speed (the ship(s) and the astroid(s)) if the ship can’t avoid collision, a collision is ok. I just want to make them a little smater then just following a math sinus path.

Any Ideas how to do that?

Best regards,

Meshes are Spaceholders right now: Astroid from S2 from Blendswap and the Main Ship from Herminio Nieves

You could try have the enemy ships do a trace in front of them, if the trace returns an asteroid then move x units right/left.

I know that sounds way too simplified and it’s probably not the best way at all but assuming you don’t want them to be super “smart” then maybe you could get something that works “ok” by expanding on that idea.

Thanks TK Master, because the astroids are moving from up to down in different angles and speed there can be some of them are faster then the little attacker ship(s). But after your post I now tried to use Sphere Trace by Channel and that seems to work. I was unable to make start and end point of the trace the same but if I vary it just by two units it works fine. (Just have to implement the collision avoidance logic now).

Is a trace made every frame? From the debug drawings one could think it is made every second?

Best regards,

Yeah a trace can be made every frame if you need to (if it’s been executed by the tick event for example) the debug drawings have a parameter for how long they stay on screen so maybe try and adjust that.