Devblog 6 – Bullet logic

Bullet logic


Hey, Domen here. My task was and still is to create at least reasonable bullet logic which is “kinda” realistic. For starters lets define what a bullet is. For the first N metres (or any other unit) the bullet reacts and is defined as a raycast from an origin point to a direction – in most cases a gun barrel or the middle of the screen (crosshair position). If nothing is hit then proceed with so called partly raycasts – cast a short raycast and if nothing happens move the origin of the previous ray to an end position of that ray.

Here is an ugly paint sketch (:P):

bullet logic standard floatlands
standard bullet logic

This got me quite a satisfying result but I wasn’t happy with it. Bullet isn’t only a ray, it has a volume and there is also gravity that affects the movement of the bullet.

basic raycast lowpoly floatlands
implementation of basic raycasting system

The next thing was to implement basic gravity impact to the bullet. I also moved every physics call to the FixedUpdate() so the Unity physics has the time to refresh itself. I also added a simple TTL (Time to live) system, so the bullet “dies” at about 25 raycasts.

gravity affected bullet floatlands
gravity affected bullet

Here is an example of an instant raycast (black ray) and the partly raycasts (red) which the gravity affects, kinda heavy bullet eh? The next stop was implementing the volume of the bullet, which is a simple raycast towards every directon. We can now change the gravity affection, bullet spread, bullet time to live and bullet speed, which is nice if we want to implement some sort of mortars, snipers, or weak pistols. Aaaaand the final result:

drone attack lowpoly floatlands
poor drones getting attacked

Join us on Discord

1 Comment

  1. Ruan says:

    You can use SphereCast or volume.

Leave a Reply

Timelapse #7: RoboDog modeling and rigging

Floatlands Wikigamepedia lowpoly floatlands

Floatlands, lowpoly, survival

Floatlands, lowpoly, survival