added Nic's collision pseudocode
This commit is contained in:
parent
363f28cb9c
commit
fde99ef76b
27
design/collision-PseudoCode.txt
Normal file
27
design/collision-PseudoCode.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
checkCollision(movingRect, moveVector, solidRect)
|
||||||
|
{
|
||||||
|
// Need to make additional similar checks for each side
|
||||||
|
if (moveVector.x > 0)
|
||||||
|
{
|
||||||
|
if (movingRect.xMax < solidRect.xMin &&
|
||||||
|
movingRect.xMax + moveVector.x > solidRect.xMin)
|
||||||
|
{
|
||||||
|
xHitRatio = (solidRect.xMin - moveingRect.xMax) / moveVector.x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Also find hit ratio of y movement and see which one will hit first if either does.
|
||||||
|
if (xHitRatio < yHitRatio)
|
||||||
|
{
|
||||||
|
yHitPosMin = movingRect.yMin + moveVector.y * xHitRatio
|
||||||
|
yHitPosMax = movingRect.yMax + moveVector.y * xHitRatio
|
||||||
|
if (yHitPosMin < solidRect.yMax &&
|
||||||
|
yHitPosMax > solidRect.yMin)
|
||||||
|
{
|
||||||
|
// We know here now where we should collide, however if we stop here the collision will feel 'sticky'
|
||||||
|
// rather than just applying the ratio to the movement vector, we want to instead slide along the collision
|
||||||
|
output.x = movingRect.xOrigin + moveVector.x * xHitRatio
|
||||||
|
output.y = movingRect.yOrigin + moveVector.y // Here is where we should split off a new movement vector to check collision again really, since it is a new direction to check, so return the hit position with a new smaller vector to 'finish' the movement.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user