Small update with physics and selection

Just documenting my progress :)

Physics

I basically took the car physics set up by an earlier HTML5 project and made some adaption, so the cars align with the terrain underneath. The physics and everything are still in 2D, but I added a check when a car jumps, so it changes the physics there to just continue the current path and add gravity to the Z-Coordinate. With car jumping I mean when it drives over a dune / hill to clarify. My cars don’t jump otherwise. Yet?!

The AABB Collision i set up in my HTML5 game is working here as well, it’s 2D, again.

The impulse and rotational input when cars collide are only on the 2D axis, but I check height differences when checking for collision, so cars can jump over each other.

The whole physics are set up time corrected, so framerate doesn’t increase speed. The video above I set the timeSteps to 30ms (~33 FPS) (from the default 16.66ms (~60FPS)) and it works as expected. Same with 1 ms (1000fps). It’s the way it should be obviously, but i didn’t bother in previous projects.

Selection

The selection of cars is pixel perfect, which I think was an easy robust solution instead of some raycasting.

I use the car id and translate it to a color value (0 –> {0,0,0}, 256 –> {1, 1, 0}) and then draw only the models with the pixel shader only applying this color value to a new renderTarget.

I can read out this renderTarget at the mousePosition and by transforming the color back to an int get the ID of the entity I hover above.

image

(in the picture above this is visualized. Usually all these cars would be almost black, since the ids start with 1, but for clarity I increased the start and difference values)

EDIT: April. I don’t use this any more. Was reliable but slow to read out textures. Basically relying on raycasting right now. Just sayin :D

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s