I am trying to make a simple shooter game, where a tank is shooting (in a top down view) projectiles. The problem I am encountering is the ball sometimes bouncing inside the object or the wrong way. I have checked through many forums, and one of them comes close to what I need, although it fails at bouncing off any angle correctly. I am trying to make it as accurate as the "If on edge, bounce" block.
I think part of the issue might stem from how the projectiles are most likely moving a little each frame, making it very possible for them to go inside objects. You can try to get around this by doing something like this before running the bounce script.
When the ball goes into the wall, backtrack until the ball is just outside the wall, or at least touching the very edge, then do the bouncing calculations.
Alright, ill try that, thank you
One thing is, IF ON EDGE BOUNCE is mathematically easy because the edges of the stage are horizontal or vertical. If you really want to get the angle right for bouncing off a sprite, you have to compute the tangent to its costume at the point of collision. People mostly aren't that fussy.
is there a way to similarly recreate this? or at least some simple solution to make it at least bounce somewhat accurately?
Well, I guess you could work out which edge of the costume's bounding box you crossed to reach the collision point and pretend you're bouncing off that edge to compute the angle. (I haven't tried that, though.)
you can probably copy a lot of code from the definition of the if on edge, bounce block :)
also, can you please share your project?
look this project, maybe this could help...
this helps, although after messing around with it for a little, it is hard to imitate this while shooting from any angle, and I'm not looking for something with gravity
That's a cool game !
thanks