Skip to content

Fix FPS-dependent movement in Navigation AStar demo #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions 2d/navigation_astar/character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func _ready() -> void:
_change_state(State.IDLE)


func _process(_delta: float) -> void:
func _physics_process(_delta: float) -> void:
if _state != State.FOLLOW:
return

Expand All @@ -44,6 +44,7 @@ func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed(&"teleport_to", false, true):
_change_state(State.IDLE)
global_position = _tile_map.round_local_position(_click_position)
reset_physics_interpolation()
elif event.is_action_pressed(&"move_to"):
_change_state(State.FOLLOW)

Expand All @@ -52,7 +53,7 @@ func _move_to(local_position: Vector2) -> bool:
var desired_velocity: Vector2 = (local_position - position).normalized() * speed
var steering: Vector2 = desired_velocity - _velocity
_velocity += steering / MASS
position += _velocity * get_process_delta_time()
position += _velocity * get_physics_process_delta_time()
rotation = _velocity.angle()
return position.distance_to(local_position) < ARRIVE_DISTANCE

Expand Down
1 change: 1 addition & 0 deletions 2d/navigation_astar/game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ texture = ExtResource("6_b3lcn")

[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2(576, 324)
process_callback = 0
5 changes: 5 additions & 0 deletions 2d/navigation_astar/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ move_to={
]
}

[physics]

common/physics_ticks_per_second=120
common/physics_interpolation=true

[rendering]

renderer/rendering_method="gl_compatibility"
Expand Down