0 votes

So, I'm updating players position with the following code, so I can limit it's velocity.

position += (get_global_mouse_position() - position).normalized() * 30

But when the mouse is over the player, but, mininal or no movement are made at all, it starts shaking up and down as you can see in the gif bellow.

enter image description here

So, if someone could help me understand why this is happening and how to fix it, it would be very nice.

asked Mar 29, 2018 in Engine by Jutoend (34 points)

1 Answer

+1 vote
Best answer

Your code is adding 30 pixels to the position in the direction of the mouse. But if the mouse is closer than 30 pixels, then you're going to move 30, be past the mouse, and then move 30 back. You should only move if you're more than 30 pixels away from the mouse, or even better, move a smaller distance when you're closer to the mouse.

answered Mar 29, 2018 by kidscancode (17,776 points)
selected Mar 29, 2018 by Jutoend
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.