Bullet positions getting set to NaN

Get help using Construct 2

» Tue Oct 29, 2013 11:39 pm

Hey all, I have some objects in my game with the bullet behavior that I'm doing a lot of stuff to (disabling and enabling bullet, bouncing off of certain objects, adjusting positions and angles, pinning, unpinning, changing speeds and accelerations, etc.)

I'm running into an issue where every now and then a bullet object's position will be set to NaN by something (both x and y values). I haven't been able to repro it reliably, but I do notice it often happens when a bullet decelerates to 0. When it gets to the point where I expect it to stop, it will vanish, and checking the debugger reveals that the object still exists but has NaN as the position.

The project is kind of large and sprawling so I can't easily link it, but was just wondering if anyone has run into this issue or had suggestions for debugging to try and figure out why the position is getting set to NaN, or if there's a way the bullet behavior can end up dividing by 0 or whatever.

Thanks!Wertle2013-10-29 23:43:06
B
11
S
2
Posts: 87
Reputation: 1,112

» Wed Oct 30, 2013 12:02 pm

You are probably doing a calculation that results in NaN. 0 is a common case where things go wrong: divide anything by 0 and you'll get infinity or NaN, and then passing that result to other calculations can result in more NaNs.
Scirra Founder
B
413
S
244
G
92
Posts: 25,073
Reputation: 199,682

» Wed Oct 30, 2013 5:08 pm

What would be the most likely input culprits for divide-by-0 calculation with the bullet behavior? Speed? Acceleration? Position? Angle?
B
11
S
2
Posts: 87
Reputation: 1,112

» Wed Oct 30, 2013 5:32 pm

I have narrowed it down to the Bounce event. If I manually bounce something off an object while it is decelerating, when the speed reaches 0 it will sometimes get NaN as its position (but not always).

@Ashley - I'll continue to try and isolate the issue and see if I can get a repro-able .capx, but does anything jump to mind knowing this?
B
11
S
2
Posts: 87
Reputation: 1,112