EN
Magomet Kochkarov
Magomet Kochkarov
1 subscriber
goals
947.36 of $ 1 145 money raised
Eat

Moving in circles with collision detection

Hey!
Recently my subscriber requested a very challenging movement code. He wanted to have a player controller that would move in circles but with collision detection. The challenging part is that collision detection provided by the game engine is linear! Means that player would always end up moving out of the circle...
After spending a night with this challenge, I came up with a tricky but nicely working solution! Instead of trying to move the player directly in circles, I move it towards the point on the circle!
This is how I did it (picture below):
* find 'angle' at which player is currently standing relative to the circle via atan2(y,x)
* from that 'angle' find position on the left and on the right of the player
* move player towards that position but only if we have input from player
This is how it looks like at the end!
All the features of the build in collision detection are working!

Subscription levels

Basic subscription

$ 0,12 per month
Buy me a coffee
Go up