I’m attempting so as to add a click on to maneuver characteristic in my recreation utilizing the brand new NavigationAgent2D and NavigationPolygonInstance.
It works effectively for probably the most half however my participant begins shaking virtually randomly when I attempt to transfer it across the map:
The logic to maneuver the participant is fairly straight ahead:
Player.tscn
extends KinematicBody2D
export var MAX_SPEED := 250
onready var navigation_agent := $NavigationAgent2D
var velocity := Vector2()
func _ready():
set_target_location(place)
func set_target_location(goal: Vector2) -> void:
navigation_agent.set_target_location(goal)
func _physics_process(_delta):
if navigation_agent.is_navigation_finished():
return
var move_direction = place.direction_to(navigation_agent.get_next_location())
velocity = move_direction * MAX_SPEED
navigation_agent.set_velocity(velocity)
func _on_NavigationAgent2D_velocity_computed(safe_velocity):
velocity = move_and_slide(safe_velocity)
World.tscn
extends Node2D
onready var participant := $Player
func _input(occasion):
if occasion is InputEventMouseButton and occasion.pressed:
var target_location = get_global_mouse_position()
participant.set_target_location(target_location)
I feel it might be one thing associated to the polygon itself however I can not discover any apparent points, here is how I set it up:
The essential problem is that velocity is rarely set to zero so the participant by no means stops, logging the safe_velocity
reveals output like this:
(1.379092, 199.995239)
(-1.37875, -199.995255)
(1.379092, 199.995239)
(-1.37875, -199.995255)
...
I created a repo with some minimal code to breed the difficulty, hopefully it might assist:
https://github.com/jahvi/godot-sample
Can anybody recommendation how you can eliminate this shaking?
Thanks.