Greetings again, sorry for posting so frequently as of lately
I’m making a prototype game where I have an object that moves kind of like an asteroids ship, with things like moving away from the mouse, slowing down when nothing is pressed, etc etc
That being said, I want to make my object “bouncy.” As in they’ll bounce away from a solid wall if they bump into one.
So I got to work, but I quickly ran into a problem…
See, instead of using forces, I use positions instead. The forces just don’t give me the movement I’m looking for (Unless I’m missing something), which is why I favored positions for the movement. I use VX and VY variables to track positions to adjust speed here.
However, since those values fluctuate into positive AND negative values often, I feel like there might not be a workaround for the bounce system I have in place…
Here’s the code, and a preview of what’s happening so far:
So currently, the code has two main problems:
Since the checks comparing the VX and VY only test if the values are GREATER than each other, the bouncing only works one way. As you can see, I can only bounce off of the right wall and floor. Touching the left wall and ceiling do absolutely nothing. I didn’t add these because I’m afraid if I add values that check for lesser values, it’ll conflict with the greater than values, causing NOTHING to work…
(If I use less than, the body will bounce off of the ceiling and left wall instead)
It might not be obvious, and it might be hard to explain, so I’ll draw an example:
Basically, the body doesn’t bounce realistically off of surfaces if it hits it at a certain angle and value.
Let’s say that if I’m about to hit the floor, but my VX (Horizontal speed) is higher than my VY (Vertical speed), then I bounce straight backwards instead of realistically.
Unfortunately, I cannot use the bounce extension for this, because, well, the bounce extension relies on FORCES, that of which I’m not using.
That’s where I’m stuck. Is there a way to simulate realistic bouncing for ALL surfaces with the position setup I have right now? Or is there a way to convert this faithfully using forces instead (That way I can just use the bounce behavior)?
Any help is appreciated, thanks