How laser weapons work in Ruined Horizons


In Ruined Horizons, lasers are one of the available weapon types you can fit on your ships. Laser weapons have many advantages and a few disadvantages. Advantages are that they are very accurate weapons, have a very long range, and have infinite ammunition (so long as you have enough power to run them).

Speaking of power, one of the main disadvantages of laser weaponry is that it is very power hungry and the lasers damage falls off over distance. All this is to say that you need to think carefully before adding them to your ship, and be tactical in their use in the battlefield. 

I recently added the ability for laser weapons to miss their targets (as previously they were 100% accurate all the time) and this has prompted me to write this short post explaining how laser weapons in the game work in case anyone is interested!

Firstly there are a few things to take into account, the three most important for this post being maximum range, falloff start and maximum damage. When a laser is fired at a target (and hits it), the base amount of damage done to the target is calculated. Laser damage falls off over distance, so first we need to calculate the distance to the target. At a lasers max range the beam will only do 10% of the max damage it is capable of. However, there is a also a Falloff Start variable, which is the range that the laser will do full damage at BEFORE it starts to fall off. 



In the above example, this weapon has a max range of 300km with a falloff start of 75km. That means that between 0 and 75km the beam will do full damage to any target it hits. After 75km, the damage will reduce linearly down to 10% of it's max damage at 300km.  Once we have the range to the target, we can work out if it is within the falloff start value of the laser. If so, we simply return the full damage of the laser at this point.  If it's beyond this point, we calculate the damage from the falloff to the impact position and reduce the damage accordingly.

By tweaking these variables we can create a number of different laser weapons with differing characteristics. For example, we could create a "Focused Laser" which would have a high falloff start value, but be more power hungry and expensive to run, or we could create an "Extended Range" laser that gives up hitting power in order to gain range, etc.

How to determine where the beam goes...

In the game, beams are rendered using this general procedure:

1. Point the beam turret at the target

2. When the turret is within some small tolerance of the target determine the beams impact point. This is done by picking a random position within a sphere where the target is at the centre. The size of this sphere is determined by the turrets inaccuracy rating and the targets evasion rating. The higher these are, the bigger the sphere is.

3. Line cast from the barrel of the turret, along the direction it is facing to the maximum range of the beam.

4. Determine if we hit anything along the way. If not, we render the beam to that location (this is a miss).

5. If we did hit something, determine if it was a ship, or some other obstacle (used later for damage calculations) 

6. If we hit a ship, determine the distance to the impact point. 

7. Calculate the damage we have dealt using the procedure outlined above.

8. Finally, render a line between the turret barrel and the impact point and apply the appropriate material for the desired visual effect.

And that's it! Now we have lasers!

Get Ruined Horizons

Leave a comment

Log in with itch.io to leave a comment.