LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Any good tutorials for collision?

Root / Programming Questions / [.]

ResetReloadCreated:
Can't seem to find any complete or in-depth tutorials to this.

I've attempted it only with one method: store the initial position in coordinates, and then the next position, and determine if any collisions occurred between the two points. The latter part is the part which seems to stump me most at times. Another method is to calculate the velocity of the position which is to be moving, then anticipate where the position will be on the next frame, and determine if a collision will occur then.

store velocity and old velocity and when a collision happens then restore velocity to old velocity

store velocity and old velocity and when a collision happens then restore velocity to old velocity
Well, that'll put you in an endless loop. Store one velocity, then when a collision happens, invert the velocities based on the direction you are moving. If you are moving up and strike an object, multiplying the velocity by -1 would reverse its direction. You want to calculate the direction (either positive or negative direction) of the position you are performing collision on for every frame. An X and Y direction, because you can be moving either up or down while you are moving either left or right. If you, for instance, strike a floor, you want to multiply the Y velocity by -1 so it moves up while maintaining its X velocity (you could, however, multiply the X and Y velocities by some fraction during this collision, like 0.7 or something, to mimic friction). If it strikes a wall, you want to multiply its X velocity by -1. Generally, if collision @ wall then VELx=VELx*-1 if collision @ floor or ceiling then VELy=VELy*-1

store velocity and old velocity and when a collision happens then restore velocity to old velocity
Well, that'll put you in an endless loop. Store one velocity, then when a collision happens, invert the velocities based on the direction you are moving. If you are moving up and strike an object, multiplying the velocity by -1 would reverse its direction. You want to calculate the direction (either positive or negative direction) of the position you are performing collision on for every frame. An X and Y direction, because you can be moving either up or down while you are moving either left or right. If you, for instance, strike a floor, you want to multiply the Y velocity by -1 so it moves up while maintaining its X velocity (you could, however, multiply the X and Y velocities by some fraction during this collision, like 0.7 or something, to mimic friction). If it strikes a wall, you want to multiply its X velocity by -1. Generally, if collision @ wall then VELx=VELx*-1 if collision @ floor or ceiling then VELy=VELy*-1
oops, i meant restore velocity to 0