How to fix the characterbody2d jitter
Asked Answered
D

3

0

My problem is that I have a characterBody 2D, and I want it to move following my vector2 coordinates. However, during the movement process, I noticed that it experiences jittering in all directions.
I've read many articles related to issues with Camera2D, but I'm not using a camera.

Currently, I've tried:

  1. Limiting the FPS to 60.
  2. Moving the code from _PhysicsProcess to _Process.
  3. Adding delta.

None of these changes have resolved the jittering issue.

The jittering issue is particularly noticeable when the target is set to new Vector2(0,100), but it's not very apparent when the target is set to new Vector2(100,100).
This is the record

My sprite2d texture is using the default icon.svg

Below is my code

    public override void _PhysicsProcess(float delta)
    {
		
	var targetPosition = new Vector2(0,100);

	fsm.NPCNode.Velocity = fsm.NPCNode.Position.DirectionTo(targetPosition) * speed;
	
		
	 if (fsm.NPCNode.Position.DistanceTo(targetPosition) > 5)
        {
             fsm.NPCNode.MoveAndSlide();
         }
    }
Discuss answered 2/3 at 2:39 Comment(0)
D
0

I change the vsync/vsync_mode

disable the v-sync and the issue fixed

Discuss answered 4/3 at 10:40 Comment(0)
K
0

Discuss you are not using delta. You need to incorporate delta into your movement to smooth it out or else the base performance of your system will highly effect the on-screen movement.

Pardon, I am not as good at C and used to GDScript, but this should work. You may have to increase your speed variable as the delta tends to reduce the movement speed overall when calculated as it's a float.

    public override void _PhysicsProcess(float delta)
    {
		
	var targetPosition = new Vector2(0,100);

	fsm.NPCNode.Velocity = fsm.NPCNode.Position.DirectionTo(targetPosition) * speed * delta;
	
		
	 if (fsm.NPCNode.Position.DistanceTo(targetPosition) > 5)
        {
             fsm.NPCNode.MoveAndSlide();
         }
    }~~~
Kwei answered 2/3 at 19:50 Comment(0)
D
0

I add the delta , but the issue still there.

That's pretty weird 🙁

My goal is want my character keep walking through the same path.
When I set only to one point (0,0) to (100,0), this issue didn't occur.
But if I set from (0,0) to (100,0) to (100,100) , the issue occur.

Discuss answered 3/3 at 11:11 Comment(0)
D
0

I change the vsync/vsync_mode

disable the v-sync and the issue fixed

Discuss answered 4/3 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.