Changing Direction #34
Replies: 5 comments 2 replies
-
1. Decide what kind of collision was there left/right wall or the floor?2. Document the axis at which the ball hit a wall/floor (x, y).3. Document the angle of hit and determine the new angle to go by.4. Go by that angle, and take lose of speed into consideration. |
Beta Was this translation helpful? Give feedback.
-
1. Decide what kind of collision was there left/right wall or the floor?Declare an byte(int) variable, which have the following attributes:0 = no collision | when none of these are true ↓: 1 = right wall | if (x + width >= screenX) 2 = left wall | if (x <= 0) 3 = ground | if (y + height >= screenY - groundHeight) |
Beta Was this translation helpful? Give feedback.
-
2. When one of these happen ↑, I'll update colX/Y in the same function.For example:
|
Beta Was this translation helpful? Give feedback.
-
3. Document the angle of hit and determine the new angle to go by.This part is a bit more complex so I'll visualize:
|
Beta Was this translation helpful? Give feedback.
-
4. Go by that angle (colAngle), and take loss of speed into consideration.BUG: when the ball hits the wall, it moves accordingly, but not from colX/YDESC: when the ball collides it immediately teleports to initial point: |
Beta Was this translation helpful? Give feedback.
-
How do I make the ball change its trajectory after hitting a wall or the floor?
Beta Was this translation helpful? Give feedback.
All reactions