Hey, I'm trying to make a basic hockey style game. I have the basic physics working with the pitch, a player, an opponent, and a ball.
I'm struggling to figure out how I can allow the ball to travel into the goal while keeping the player and opponent from going into the goal.
Basically the opponent follows the ball, and the player is controlled by user input. so there are two restrictions I need.
I need to create a shape that only the ball can go through... is this even possible? Maybe I can sleep the opponent if the ball passes the goal line?
Am I going about it the right way?
Player1 can only move around in the red box Player2 can only move around in the green box The ball can move around in the outer blue box
If you're using Box2D, you probably want to look into Sensors.
Taken from the Box2D Manual:
Sometimes game logic needs to know when two fixtures overlap yet there should be no collision response. This is done by using sensors. A sensor is a fixture that detects collision but does not produce a response.
You can flag any fixture as being a sensor. Sensors may be static or dynamic. Remember that you may have multiple fixtures per body and you can have any mix of sensors and solid fixtures.
Sensors do not generate contact points. There are two ways to get the state of a sensor:
- b2Contact::IsTouching
- b2ContactListener::BeginContact and EndContact