Skip to main content

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password
Register
  • Home
  • Browse
    • 2D Art
    • 3D Art
    • Concept Art
    • Textures
    • Music
    • Sound Effects
    • Documents
    • Featured Tutorials
  • Submit Art
  • Collect
    • My Collections
    • Art Collections
  • Forums
  • FAQ
  • Leaderboards
    • All Time
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
    • Weekly
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
  • ❤ Donate
FLARE [ARCHIVED]

sliding movement on collision detection

Anonymous
Monday, April 9, 2012 - 23:12

May I know how it works? I believe this is where the movement and collision detection happens - http://d.pr/gnQM

 

I have an idea how it works though - it looks like:

1. your not doing timed-based movement, but rather pixel by pixel.
2. until "speed" or "distance" is met - you will loop through x and y player position and increment it every loop depending on a set of condition. the function finishes with the x and y position incremented for the current frame
 

I'm particularly interseted in the sliding - absolute stop is pretty much straightforward. Also my difficulty problably also lies because on my game i'm doing timed-based movement.

Can you explain how your sliding and movement technically works please?

  • Log in or register to post comments
Clint Bellanger
joined 15 years 9 months ago
Thursday, April 19, 2012 - 15:53
Clint Bellanger's picture

This function is a specific case. In my game movement happens in 8 direction.

When this function is called, step_x and step_y will be -1, 0, or 1. These basically define which direction the movement happens. dist is the total desired movement distance.

For the entire desired distance I move 1 unit (sort of like map pixels) at a time. I check to see if the next coordinate is open, and move one unit if it is.

If the next coordinate is blocked, and I'm moving diagonally, I try "sliding" along the wall. This means instead of checking in the (step_x,step_y) direction, I check (step_x,0) and (0,step_y) to see if those spaces are open. If so, just move in either X or Y instead of both.

TL;DR: if I can't move in the desired X,Y direction, try moving in just X or just Y. 

In a time-based game, your Distance input will be variable based on delta_time since the last frame. That will be calculated before calling a function like this.

--

More thoughts:

This function returns False if it wasn't able to move the full distance. The calling code will change the entity's state from Running to Standing when this function returns false.

  • Log in or register to post comments