Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Map collision

    Help
    2
    3
    215
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • LinkCraft
      LinkCraft F last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • Willpowered
        Willpowered Fuze Team last edited by

        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!

        1 Reply Last reply Reply Quote 8
        • LinkCraft
          LinkCraft F last edited by

          Thank you that was exactly want I needed. I was over here messing with 30+ lines of nonsense.

          1 Reply Last reply Reply Quote 2
          • First post
            Last post