- Edited
How do I make so that a RigidBody2D, that follows my mouse doesn't go in/trough walls and go crazy
here's what i mean, so that doesn't happen
[
How do I make so that a RigidBody2D, that follows my mouse doesn't go in/trough walls and go crazy
here's what i mean, so that doesn't happen
[
TheGuyWithName Please post your code that you have for moving your rigid body. Rigid bodies ought to really be moved by physics impulses rather than directly. My guess is you are directly moving it, thus causing it to ignore collision shapes.
Other questions, do your walls have collision shapes and set up I same layer/mask as your rigid body?
`func _physics_process(delta):
#when item clicked it follows mouse
if selected == true:
global_position = lerp(global_position, get_global_mouse_position(), 25* delta)
look_at(get_global_mouse_position())
gravity_scale = 0
if Input.is_action_just_pressed("Delete"):
queue_free()
if level == 1:
Globals.lvl1itemsOnTable -= 1
if level == 2:
Globals.lvl2itemsOnTable -= 1
func _input(event):
#when mouse released item drops
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
selected = false
gravity_scale = 1 `
the walls are in different layer from rigid body
TheGuyWithName Okay, first if you want collision with walls as in you want rigidbody to hit walls it needs to have the same collision mask as the walls layer.
Second, it is vest not to directly change a rigidbodies position like you are doing.
Use set_linear_velocity((get_global_mouse_position() - global_position) * (25 * delta)) try this and see what happens.
xRegnarokx It worked, thank you very much!! Almost gave up on the game, but then remembered that this site exists. I also checked if it needs to be on the same layer, it doesn't.