# Camera collision with walls

I’m trying to make a game with a third person camera that collides with walls, and then slides back to it’s initial position once the collision is over.

I have already have a collision sphere attached to the camera that is keeping it from moving outside the room, but I don’t know a good way to cause the camera to slide back to it’s initial position once the collision is over. Any help would be appreciated!

I would suggest having a task (or a section of code in an extant task, if you prefer) that continually attempts to push the camera towards its default position. This might involve a stored velocity vector and the application of a force (multiplied by the frame’s dt) as long as the camera is not at or beyond the desired default position; a little bit of creative maths might allow you to scale the force such that it decreases as the camera approaches the desired default position, thus (hopefully) slowing the camera to a stop. The collision system should prevent the camera from passing through the walls, and the force should move the camera when there is no wall in the way. Finally, consider adding an event callback to your camera collisions allowing you to zero the camera’s velocity on collision, thus (perhaps with some tweaking) providing a “soft” start for your camera movement.

What would be the best way to go about giving it some sort of constant velocity towards a point? I’ve been trying to use intervals, but they do not cooperate with the collision system very well.

Try a task, combined with a variable in which to store your velocity (since the desired velocity vector will may change depending on the position of the camera); just add to your camera’s position your velocity vector multiplied by the frame’s delta-time (for which the Global Clock should work). If you’re unfamiliar with tasks, the manual gives explanations and examples (and indeed the Global Clock is mentioned there too), I believe.