Hazard moving way to fast

I’m following the “Moving the Hazard” lecture on the C++ fundamentals and my hazard is crazy fast. I’ve tried the lecture’s velocity for the hazard (-600) and the next lecture’s velocity (-200) and both is crazy fast. On the first frame the X position is at 512px and the next frame it’s less than 0, going entirely through the screen in one frame

Hi Pedro,

Are you multiplying the nebula’s velocity by deltatime? nebVel * dT

Yep. I think that that problem might come from there (don’t know why, tho) because sometimes when I debug the value of dT it shows something like 13. …, and that multiplied by the -200 gets something out of the window

dT should definitely not be that high.

I have no idea why it’s that high.
Here is how my code is set up
image

Can I see all of your code? Would allow me to test it here and see if it’s a system issue or not.

Yeah, sure. https://pastebin.com/gNshwBvK

The problem wasn’t that your nebula was moving too fast (more on that in a moment), but that your nebula wasn’t being drawn correctly.

First, textures\12_nebula_spritesheet.png should be textures/12_nebula_spritesheet.png

Second, you’re using nebulaRec to initialize nebulaRec. Which is setting it’s height and width to 0. So Rectangle nebulaRec{0.0, 0.0, nebulaRec.width / 8, nebulaRec.height / 8}; should be Rectangle nebulaRec{0.0, 0.0, nebula.width / 8, nebula.height / 8};

As far as dT being so high is concerned. Turns out that happens because Raylib calculates the time spent while paused (due to breakpoint) as part of the delta between frames. So if you went 12 seconds paused and then hit continue, dT would end up being 12.

Thanks a lot for the help! Didn’t noticed the \ and / confusion and the nebulaRec situation

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms