I'm making a slightly modified version of my collision detector that will return what side the collision happened on, but it tells me I'm missing a return statement, even though I've made an "else return". What is wrong in this:
Do I maybe have a bracket in the wrong place? It's my understanding that if I have the "else" statement, this should work. Any help appreciated :D!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public String detectCollisionReturnSide( int moveSpeed, int xMomentum, int yMomentum) { NonPassable object; if (getOneIntersectingObject(NonPassable. class ) != null ) { object = (NonPassable) getOneIntersectingObject(NonPassable. class ); if (object.getY() >= (getY() - 15 )) //gives angled illusion { if (xMomentum > 0 ) //moving right { return "CollidedRight" ; } if (xMomentum < 0 ) //moving left { return "CollidedLeft" ; } if (yMomentum > 0 ) //moving down { return "CollidedDown" ; } if (yMomentum < 0 ) //moving up { return "CollidedUp" ; } } } else { return "noCollision" ; } } |