Jump to content

Collision on different 'heights' (z-depth) in a top-down view game (pinball)


george
 Share

Recommended Posts

Hi everyone,

I'm currently preparing the different collisions in a pinball game. I guess I won't have any problems with bumpers und slingshots. I plan to integrate a ramp and there the fun starts :)

 

The problem with a ramp: It's schizophrenic from the view of collision behaviour.

Attached you can see my current draft for the ramp. This is what I'm going to try now.

 

1. Default Behaviour:

It's a place on the stage which should not collide with the ball (as it have space below it like a bridge)

2. Ramp behaviour:

The ball can enter the ramp. Now the ball should collide with outer bounds of the ramp so that the ball can't leave the ramp. The ball is walking on the imaginary bridge.

3. Lower ramp behaviour:

The ball will roll on the ramp and at some point the ball will enter the area where the ramp crosses itself. Now the ball should not collide with the bounds it collided seconds before (so it can pass beneath it)

4. Exit Ramp

The ball will finally leave the ramp. So we are back at the normal behaviour (1.)

 

post-5762-0-83268500-1395309377.png

 

As you can see in the attached image I plan to use some sensors. When the ball hits a sensor I now the location of the ball. I could toggle the collision MASK of the ball so it collides only with different parts of the ramp. I hope my image makes sense to you. I'm really skeptical if this will works at all.

 

Maybe you guys have an opinion or hints with this topic ? Is this ramped behaviour possible ? have you seen it in the wild in other games? Is it too much with the crossing parts of the ramp?

 

 

Thanks a lot. I really appreciate every idea and voice!

Regards George

Link to comment
Share on other sites

A little progress update.

I created a custom export & parsing for polygons so I can create different fixtures/shapes inside a single polygon. This is how I created the sensors and the different parts (to set different collisions categories) of the ramp. Next topic are the signals and the collision toggling.

 

https://github.com/photonstorm/phaser/pull/614

 

Regards

George

Link to comment
Share on other sites

  • 3 weeks later...

Follow up to this topic. I managed to build this and it works create.

See the four images attached for the structure of my ramp parts & sensors.

The show only a small part of my table as it is work in progress.

 

You can see four parts of the ramp.

The sensors (to detect where the ball is), the lower parts, the upper part and the center part.

 

In this image you can see all the sensors. The ball will enter the ramp at the lower left part of the ramp and leave it through the lower right part or through the hole in the center.

 

The three parts of the ramp are lower, upper and center. Every part is a body with some fixtures. When a part is disabled I remove the Body itself (to save calculation time).

 

These are the category bits I use. The first three are assigned to the corresponding parts of the ramp. The bits for active & inactive are used to enable or disable sensor regardless of their position on the ramp. This could be refactored to use one of the existing three bits, but it's working fine for now.

RAMP_UPPER: 0x4,
RAMP_LOWER: 0x8,
RAMP_CENTER: 0x10,
 
RAMP_ACTIVE: 0x40,
RAMP_INACTIVE: 0x80,
 

Here the parts of the ramp with a little description.

 

We want to simulate a ramp. Most of the parts are higher than the table. The ball can pass beneath the ramp in one situation and shall follow the ramp in another situation. More abstract: We need to create a controlled system where the ball can pass through parts of the ramp which collided with the ball earlier or will collide with the ball later.

 

The entire what collides with what is controlled by setting the collision mask of the ball. So you do not need to iterate through dozens of fixtures in the ramp. That's the reason why you have category AND mask bits available in P2.

 

Picture 1: Sensors

The sensor 'ENTER' is the complex one. It's not defined as a real sensor- so it can be hit by the ball. When a hit occurs I calculate the direction of the it by using the normalA in the contact equation. If the direction is top-right I disable the collision with the ball (so it can pass through) and also enable the lower parts of the ramp by setting the collision mask of the ball to RAMP_LOWER | RAMP_ACTIVE (Ramp active for the sensors).

 

post-5762-0-12845900-1397169072.png

 

Picture 2: Lower Ramp

Here you see the lower parts of the ramp activated. The ball can trigger two sensors from this state.

 

1. You can also see a big sensor 'LEAVE LOWER'. This is for the case that the ball rolls backwards if it's speed is no hight enough to reach the higher part. When the ball collides with this sensor I know it left the ramp from this side again. I save another complex direction classification with the existing enter sensor.

2. The small sensor 'TRANSITION' will disable the lower ramp and enable the upper ramp. 

 

post-5762-0-40293700-1397169071.png

 

Picture 3: Upper Ramp

You see the upper ramp activated. Notice the small nose near the transition sensor. This is to prevent the ball from leaving backwards. This makes it easier. I do not have to detect backward movements. I also marked the ENTER SENSOR.

This sensor is the same sensor like the ENTER Sensor. It collides with the ball and let it only through when the angle of enter is correct. This prevents that the ramp switches from upper to lower state when the ball pass by.

If the angle is correct it enables the center and disables the upper ramp. If not the ball will pass by and later activate the sensor LEAVE UPPPER.  The entire ramp will be deactivated.

 

post-5762-0-90960300-1397169072.png

 

Picture 4: Ramp Center

This is the center part activated. The ball can leave with the hole or through the bay it entered. The sensor LEAVE CENTER

detects when the ball leaves to the left. If the ball leaves through the hole, the teleporter action of the hole notfies the ramp so it can disable itself.

 

post-5762-0-76212500-1397169069.png

 

This was fun :)

Link to comment
Share on other sites

  • 3 weeks later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...