Saturday, September 29, 2018

Tiled Terrain Weapons and Physics

I finally got around to implementing some weapons and physics effects in tiled terrain mode. I currently have projectile intersections with the terrain and explosion effects working. Laser beam, shotgun, and M16 shots hit the terrain at the correct points. Bouncy balls can be thrown at the terrain and will bounce and roll properly. Rockets fired will hit scene objects and explode. Object physics includes gravity, air resistance, static and kinetic friction, wind effects, momentum, and elasticity.

Here is a video showing ball (sphere) physics and collision detection with the terrain. Cities are disabled for this test, leaving empty city roads and plots. I made the bouncy balls huge for these videos so that they're easy to see from a distance and from between city buildings. The large balls in this video are 9.6m (31 feet) in radius.

Who here remembers Mr Yuck, the green face I'm using as a texture for some of the balls?

Here's a video showing balls, rockets, and grenades colliding with and bouncing off city buildings. Note that collision with cars, streetlights, and traffic lights is also enabled, but is difficult to see with these huge balls. Collisions currently have no effect on the city elements.

Sorry, the video is playing back too quickly. Drawing all of the buildings, cars, grass, etc. at the same time as realtime video capture and compression couldn't quite keep up with my target 60 FPS recording rate. I disabled some unnecessary effects such as water reflections for the later videos. [Yes, there is water, but it's all behind the mountains and not actually visible. The occlusion culling has a hard time on this high frequency eroded terrain.]

After recording this video, I noticed that the collision detection isn't correct for some of the oddly shaped buildings. I fixed the problems and recorded another similar video. I even added some bouncy plasma balls near the end. Here it is. If you're going to read the text but only watch one of these videos, this one is probably a better choice than the one above. I have them both here to show my incremental progress.

Here's a video of me throwing cluster grenades into a city. Note that the buildings, cars, etc. aren't yet destroyable. That will be shown later in this post. Also, I haven't yet had a chance to add dynamic lighting from weapons to cities (or tiled terrain mode in general).

The thousands of grenade fragments collide with and land on the buildings. If you look closely you can see the bright particle trails of the glowing fragments. You might have to pause the video to see these clearly. This is a new graphics feature that I added while working on tiled terrain physics that's built on top of the laser beam drawing system.

Here I've added fire and more smoke. Fires burn at the terrain height, which in this case is at the elevation of city roads and plots. They don't climb up buildings like they do in regular ground mode gameplay. I might add something like that later. Smoke also isn't affected by buildings like it is in ground mode.

I didn't record any sound for these videos, but you'll be happy to know that this test is full of explosion sounds, especially in the one below.

Those explosions are nice, but they don't have any effect on scene objects. They're purely visual. Let me make those cars destroyable with zero hit points. One hit and they explode. In fact, blast radius damage can destroy multiple nearby cars in one hit. There, that looks better. Unfortunately, I forgot to re-enable building shadows in this video.

As you can see, cars don't react to other cars exploding around them. They just drive up to fill the empty space left by the exploded car, which leaves no debris. Maybe I can have cars react to explosions as a future project. I'm not exactly sure what they would do. Maybe ignore traffic lights and try to drive away from the player or explosion as quickly as possible? If I ever add people to my cities I can have them get out of cars and run into nearby buildings. That works for them, until I figure out how to make buildings destroyable.

I would say that this solves the traffic gridlock problem. Just destroy cars when they get stuck and block intersections. Except, I think I finally solved that problem with a combination of other tricks from the previous blog posts. I could write a whole new blog post about that - but I'm not sure how many of you want to read another long post on the topic of traffic. And I'm not sure I have the patience to write one this week. I'll throw this shorter low-text post here to give everyone a break.

No comments:

Post a Comment