Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Strange math behaviour. I am just totally stuck

Author
Message
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 16th Nov 2021 10:19 Edited at: 16th Nov 2021 16:38
Hi again, my game grows very well and it start to seems a real videogame
But I am facing one of the strangest math problem in my DBP career.

Ok see the attached pictures.

There's a jet going left to bomb the soldier.
The soldier is in his Z coordinate
to this Z coordinate I add a distance where I place (for convenience in explaining the problem) a green wall. This wall is the TARGET_WALL
this target wall is always at a certain distance from the soldier.

ok the bomber flies towards the soldier, changing its coordinates but we are interested in the z coordinate (its z coordinate decreases as it flies towards the soldier).

At this point, in my plans, when the bomber's z-coordinate value becomes less than the soldier's z-coordinate + target wall distance (exactly where I visually placed the target wall), the soldier shoots at the plane.
In a nutshell I have created the limit at which the soldier understands that the bomber is in the right distance to be attacked.

------------

now here's the weird problem:
the soldier is placed randomly on the pitch. its x and z coordinates are generated randomly.
EXAMPLE OF IMAGE ONE:
Z_soldier = - 4300
Z_bombardiere = 5500 (when flying to the left, it reduces)
distance_target_wall = 5000
attack_limit = Z_soldier + distance_target_wall = 700 (where the target wall is placed)

condition for attacking the bomber:
if Z_bomber < attack_limit
... soldier attack jet bomber code ...
endif


It all seems very simple and clear right?
unfortunately in this example the attack code starts even if the variable Z_bombardiere is greater than the limit_attack variable.

So I tried and tried again, checked everything but nothing ..
then at the nth attempt the soldier was randomly placed further back (with a lower z-value).

EXAMPLE OF IMAGE TWO:
in this case
attack_limit = soldier_z + target_wall_ distance = -3500
and here the condition for the attack is met and the soldier will shoot exactly when the z coordinate of the bomber becomes less than the value of the attack_limit variable.

Therefore, EVERY time that the value of the attack_limit variable is a negative value, the attack condition is perfectly respected BUT whenever the attack_limit is positive, the condition will not be respected.

I hope I was as clear as possible in explaining to you.

Why does the "if Z_bombardiere < attack_limit" condition ONLY work correctly when the attack_limit is negative?

Thanks in advance to everyone!

EDIT:
If I put the attack condition inside the main loop instead inside the actual GOSUB code then the attack condition work fine.. mmmmm
currently the condition is inside a piece of code which in turn is called via a gosub from the main code and I get the error... mmm



EDIT2: I solved in this way:
the condition code must start ONLY after some "pause cicles" :

BEFORE (with math error) :


NOW (all work fine):


So using that 10 cicles pause I get all work fine and my compiler always know when Z_bomber is > or < attack_limit !

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-28 18:07:02
Your offset time is: 2024-03-28 18:07:02