RU
Magomet Kochkarov
Magomet Kochkarov
1 подписчик
цели
933.69 из $ 1 128 собрано
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!

Уровни подписки

Basic subscription

$ 0,12 в месяц
Buy me a coffee
Наверх