Godot Version
4.3
Question
So I have a scene set up with a characterBody2D which follows the mouse when I click and drag it. It works well, until the object collides with a wall, and I drag the mouse around on the other side of the wall. Here’s a video to show what I mean:
https://youtu.be/KriTEMV9Zs0
“Motion Mode” is set to “Floating”
“Wall Min Slide Angle” is set to 15 degrees. When I do this with it set to 0, the object moves up and down very rapidly, too quickly to record properly.
The code that governs this movement is as follows:
func _physics_process(delta):
#set velocity equal to vector from object to mouse.
#grabOffset = get_local_mouse_position() when object is initially clicked on. Keeps the relative mouse position consistent
velocity=(get_global_mouse_position()-grabOffset-global_position)
#Otherwise object moves very slowly. Issue persists if line is removed
velocity = (velocity.length()/4)*velocity
#Limits object velocity
if velocity.length()>3000:
velocity = 3000*velocity/velocity.length()
move_and_slide()
Cannot for the life of me figure out why this happens. Any help is very much appreciated.