position follow mouse

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

Hi learning godot3

I have a paddle. I can move it with getting mouse coordinates like
Case1:

var mouse_position = get_viewport().get_mouse_position()
set_position(mouse_position)

The problem is my KinematicBody2D will not respect the boundries of a static body, area2d. The body will simple and always follow the mouse.

Case2:

or move it via move_and_collide then it will respect my walls I placed. However if an other object hits my KinematicBody2D this will have physic effect.

How do you handle this. In case1 respect walls or in case2 have no physics on the KinematicBody2D.

:bust_in_silhouette: Reply From: rolfpancake

Use move_and_collide and then you can change the CollisionLayer / CollisionMask of your KinematicBody or the other PhysicsBodies to prevent interaction with each other.

Read more about it in the PhysicsBody2D API.

As move_and_collide returns a KinematicCollision2D-Object you can also use the included information there to adapt your bodies behavior.