0
\$\begingroup\$

I'm attempting to create a simple enemy for a platformer. It should move forward constantly until it hits something like a wall, and then it should flip and move forward the other direction. How might I accomplish this?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

There are a few ways you can achieve this.

Detecting point of collision on the Body, using a ContactListener you can listen to the contacts and react to them, by comparing the contact point from the WorldManifold to the world center of your Body you can determine if the collision happened on a side of the Body (rather than for example the bottom).

Another approach could be to add two Fixtures to the Body, one a little to the left and one a little to the right, then listen for contacts on them, this approach has the advantage of you not having to compare contact points as you know which side collided.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .