How to move a kinematic to a specific point while applying collisions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gazer500

I want a kinematic body to be limited within the bounds of a circle, which I’ve done with this function:

func circle_limits(radius: float, center: Vector2, location: Vector2, pull_force: float):
	var distance = center.distance_to(location)

	if distance > radius:
		var origin_to_object = (location - center) * (radius / distance)
		return lerp(location, center + origin_to_object, pull_force)
	return location

This works how I want it to, but since I’m using the value to directly manipulate the position of my player, it doesn’t apply any collisions when limiting the movement, causing the object to go through walls. Is there any way to use this value to limit the player within the confines of the circle while still applying collisions?

:bust_in_silhouette: Reply From: ipdramon

I asked a similar question a few days ago in the Godot Forum
The gist of the answer is to not use a lerp but the move_and_slide (or collide) function. The slide version will do the collision itself while with move_and_collide you have to do it yourself. Maybe its enough to just interchange the lerp with an appropriate call to move_and_slide and don’t call the function if the distance is too big as you already do with the lerp right now.