• entries
59
86
• views
40764

# Bullet logic & creation of a lowpoly robot

2385 views

[color=rgb(62,62,62)][font=Merriweather]

## [font=arial]Hey, Domen here. My task was to create at least a reasonable bullet logic which is "kinda" realistic. For starters lets define what a bullet is. [/font][font=arial]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.[/font]

[/font][/color]
[color=rgb(62,62,62)][font=Merriweather]

## [font=arial]Here is an ugly paint sketch:[/font]

[/font][/color]

[font=arial](standard bullet logic)[/font]

[color=rgb(62,62,62)][font=Merriweather]

## 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.

[/font][/font][/color]

[font=arial](implementation of basic raycasting system)[/font]

## [font=arial]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.[/font]

[font=arial](Gravity affected bullet)[/font]

## [font=arial]Here is an example of an instant raycast (black ray) and the partly raycasts (red) which are affected by the gravity, 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:[/font]

Our 3D artist also recorded the workflow of creating a lowpoly robot in Blender. Enjoy!

[font=arial]

# http://floatlands.net/

[/font]

Why raycast in every direction for volume as opposed to using a spherecast?  I would think the spherecast would be more performant, since you only have to do one check, but would be interested to see if that held true or not.

(Also, I'm guessing you tried the standard rigid body for bullets and found them lacking, you don't mention it, but it's not surprising, since that seems to be a common issue with Unity's physics)

We agree, it was just the first iteration of programming this and the programmer expanded it since then. I'll post an update regarding bullets soon.

## Create an account

Register a new account