Map collision
-
How do I take a sprite and let it bounce around on a map with gravity so it will stop bouncing at some point and have it bounce off of things in the correct direction and not just up and down?
-
For bouncing off the map, try something like this:
// Collide your sprite with the map collisions = collideMap(my_sprite) // If there's a collision... if len(collisions) > 0 then // Get the collision resolution (a vector representing how your sprite was pushed out of the map) res = normalize(collisions[0].resolution_a) // Get the current speed of your sprite speed = getSpriteSpeed(my_sprite) // Use reflect on it to determine the new speed, and multiply it by 0.9 so it'll stop bouncing eventually speed = reflect(speed, res) * 0.9 // Set the new speed of your sprite setSpriteSpeed(my_sprite, speed) endif
Gravity would probably look something like this:
my_sprite.y_speed += deltaTime() * 30 // You might have to play around with the number here to get the kind of feel you want
Hope that's able to help!
-
Thank you that was exactly want I needed. I was over here messing with 30+ lines of nonsense.