From 89e4dc4c2b91826160481a21fd4a10127ee9a936 Mon Sep 17 00:00:00 2001 From: Francois Belair Date: Thu, 19 Mar 2020 23:32:08 -0400 Subject: [PATCH] Fix velocity reversal bug in kinematic agents Fixes #40 --- CHANGELOG.md | 4 ++++ project/src/Agents/GSAIKinematicBody2DAgent.gd | 2 +- project/src/Agents/GSAIKinematicBody3DAgent.gd | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba651e8..af5961b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This document lists new features, improvements, changes, and bug fixes in every - Acceleration for agents are now multiplied by delta in order to make acceleration be per second instead of instant. The demos' values have been increased significantly to better fit with reality. +### Fixes + +- KinematicBody2DAgents and KinematicBody3DAgents that moved fast enough no longer reverse velocity suddenly during a frame where no acceleration is applied. + ## Godot Steering AI Framework 2.1.0 ## ### Features ### diff --git a/project/src/Agents/GSAIKinematicBody2DAgent.gd b/project/src/Agents/GSAIKinematicBody2DAgent.gd index 171e110..d8cfc45 100644 --- a/project/src/Agents/GSAIKinematicBody2DAgent.gd +++ b/project/src/Agents/GSAIKinematicBody2DAgent.gd @@ -128,7 +128,7 @@ func _on_SceneTree_physics_frame() -> void: _applied_steering = false else: linear_velocity = GSAIUtils.clampedv3( - GSAIUtils.to_vector3(_last_position - current_position), linear_speed_max + GSAIUtils.to_vector3(current_position - _last_position), linear_speed_max ) if apply_linear_drag: linear_velocity = linear_velocity.linear_interpolate( diff --git a/project/src/Agents/GSAIKinematicBody3DAgent.gd b/project/src/Agents/GSAIKinematicBody3DAgent.gd index 62b3658..b5d3665 100644 --- a/project/src/Agents/GSAIKinematicBody3DAgent.gd +++ b/project/src/Agents/GSAIKinematicBody3DAgent.gd @@ -128,7 +128,7 @@ func _on_SceneTree_physics_frame() -> void: _applied_steering = false else: linear_velocity = GSAIUtils.clampedv3( - _last_position - current_position, linear_speed_max + current_position - _last_position, linear_speed_max ) if apply_linear_drag: linear_velocity = linear_velocity.linear_interpolate(