Got a new project recently where I don't use any physics engine, but it requires some basic phyiscs. Basically it's a 2d "top-down" game type. I would like to add a smooth wall collision which feels better than those "jumping" ones. So here is how bad it looks like, I easily calulated the collision point in this way:
- Added the velocity to the player's position.
- Checked whether the new position is in the wall or not.
- Went backwards at that vector where it "came from" until reached the first non-colliding position.
Now that I have the blue position, I would like to modify the player's vector's angle with that purple angle (I guess). Because I want the next thing to happen when the player reaches that position:
- The player gets the wall's angle and walks next to it (of course only if the player still presses the key to move upwards) like in most AAA 3D games. For example TESV:Skyrim. If you are moving toward a wall or an object in a non 90° angle, then the player keeps moving but next to the wall/object.
I have already searched for solutions on Google and here aswell, but none of them fit my needs.
Would appreciate any help. Thanks!
- Green Line: Wall (Top one, the bottom one just for help)
- Purple Point: Player old position
- Blue Point: Player new position (next to the wall)
- Red Line: Vector between new and old position
Can't get it to work properly, at the edges of the walls the calculations fail. The player keeps teleporting, at the program freezes sometimes. (due the while cycles which are checking for the edges)