+2 votes

Guys I have an enemy of type KinematicBody2D which is supposed to follow player and stop at a certain distance when the player stops moving. Everything works and enemy follows player but when my player moves really slowly , the enemy starts to jitter very badly. I don't understand why ? Here's the code attached to the enemy :

var speed = 10000

onready var playerReference = get_parent().get_node("Player")

func _physics_process(delta: float) -> void:
    var direction = playerReference.get_position() - position
    var directionDistance = direction.length()
    var normalizedDirection = direction.normalized()
    if directionDistance > 80 and directionDistance <150:

The Enemy has AnimatedSprite, CollisionShape2D, Area2D as children. Also the player and the rest of the scene moves very smoothly, only enemy starts jittering when the player speed is slow. At high speed, the enemy also moves smoothly.

Godot version v3.2.3
in Engine by (415 points)

This happens to all of us sometimes :)

Can you share your project-folder?
It's hard with only snippets. sometimes the error is somewhere else.

There are not many scenes and scripts. It's a rough prototype so you should be able to take a good look at everything in a short time. I really hope you can tell me what's wrong ! I really want to understand what's causing this jittering. Also if you go ahead and increase the speed of enemy then the jittering will be more noticeable.

have you tried to remove delta and giving speed a lower value? (40 works good)
If this solves your problem, i an explain you why. If not, then something is strange, because i have no jitter at all.

Yes I removed delta and lowered the speed. Still I get jitter at high speeds. But overall I really appreciate your help :)

The problem with high speed is, that the enemy comes close very fast, then waits, because it is too close, then jumps at the player again. hope you understand what i mean...

Please log in or register to answer this question.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.