Re: Bullet Spray routines
Posted: Fri Dec 08, 2023 10:04 pm
Normalise just makes a vector have a length of 1, so in 2d it's
let length = sqrt(v.x*v.x + v.y*v.y) // Pythagoras
v.x = v.x / length
v.y = v.y / length
v.x * vx + v.y * v.y is also dot_product(v, v)
dot product just tells you the cosine of the angle between 2 vectors, as long as they are both normalised (otherwise it's length(a)*length(b)*cos(angle between a and b)).
You can use dot product for many other things though like projecting lines onto other lines so worth reading up about.
You could do super sprint AI by doing several raycasts in an arc around the car and if they hit anything try and turn to avoid collisions, so like a robot car with sensors attached. Doing the raycast is quite expensive I expect though on a speccy.
Most simple racing games either use on rails CPU or else they provide spline "tracks" like scalextric which you can use to change track for overtaking and collision avoidance etc. (so you'd have say 5 splines parallel-ish to each other and provide a routine to swap between splines as you drive along).
I think Graphics Gems is available online which has most of the maths you need to do geometry stuff like ray-circle collision, raycasts, etc.
Yup, you can read that here (dunno if that's 100% legal, mods can remove the link if it isn't)
https://theswissbay.ch/pdf/Gentoomen%20 ... ms%201.pdf
let length = sqrt(v.x*v.x + v.y*v.y) // Pythagoras
v.x = v.x / length
v.y = v.y / length
v.x * vx + v.y * v.y is also dot_product(v, v)
dot product just tells you the cosine of the angle between 2 vectors, as long as they are both normalised (otherwise it's length(a)*length(b)*cos(angle between a and b)).
You can use dot product for many other things though like projecting lines onto other lines so worth reading up about.
You could do super sprint AI by doing several raycasts in an arc around the car and if they hit anything try and turn to avoid collisions, so like a robot car with sensors attached. Doing the raycast is quite expensive I expect though on a speccy.
Most simple racing games either use on rails CPU or else they provide spline "tracks" like scalextric which you can use to change track for overtaking and collision avoidance etc. (so you'd have say 5 splines parallel-ish to each other and provide a routine to swap between splines as you drive along).
I think Graphics Gems is available online which has most of the maths you need to do geometry stuff like ray-circle collision, raycasts, etc.
Yup, you can read that here (dunno if that's 100% legal, mods can remove the link if it isn't)
https://theswissbay.ch/pdf/Gentoomen%20 ... ms%201.pdf