Page 2 of 2

Re: Bullet Spray routines

Posted: Fri Dec 08, 2023 10:04 pm
by ParadigmShifter
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

Re: Bullet Spray routines

Posted: Fri Dec 08, 2023 10:16 pm
by Wall_Axe
Thanks it's worth a look .

I suppose one way would be to project the computers car into the future if three different actions were taken and use the best.
Although if the car crashed and was facing backwards it would need to do stuff which would seem bad to a short term prediction algorithm. So maybe it could be used if the car is facing or moving in the right direction to the next invisible checkpoint.

And just loads of custom code to get a car going again...or detect a crash and teleport the enemy car back on the track.

Re: Bullet Spray routines

Posted: Fri Dec 08, 2023 11:12 pm
by lexi
ParadigmShifter wrote: Fri Dec 08, 2023 7:35 pm Missed that joke first time around lol ;) Here's 2 more
i giggled :D

Re: Bullet Spray routines

Posted: Thu Mar 28, 2024 5:34 pm
by DoctorRad
There doesn't appear to be a lot of awareness or appreciation of David Webb's book Advanced Spectrum Machine Language, which among other things, includes fast (pixel) plot and draw routines. The latter could probably be adapted into a straight-line bullet animation routine.