mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-14 04:57:19 +01:00
More cleanups.
This commit is contained in:
parent
7b9561875a
commit
a9df2d5842
@ -31,7 +31,7 @@ func _body_ready() -> void:
|
||||
# Moves the agent's `body` by target `acceleration`.
|
||||
# @tags - virtual
|
||||
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void:
|
||||
_applied_steering = true
|
||||
applied_steering = true
|
||||
|
||||
if movement_type == MovementType.COLLIDE:
|
||||
_apply_collide_steering(acceleration.linear, delta)
|
||||
@ -122,10 +122,10 @@ func _set_body(value: KinematicBody2D) -> void:
|
||||
_body_ref = weakref(body)
|
||||
|
||||
_last_position = value.global_position
|
||||
_last_orientation = value.rotation
|
||||
last_orientation = value.rotation
|
||||
|
||||
position = GSAIUtils.to_vector3(_last_position)
|
||||
orientation = _last_orientation
|
||||
orientation = last_orientation
|
||||
|
||||
if !had_body:
|
||||
if !body.is_inside_tree():
|
||||
@ -146,18 +146,18 @@ func _on_SceneTree_physics_frame() -> void:
|
||||
orientation = current_orientation
|
||||
|
||||
if calculate_velocities:
|
||||
if _applied_steering:
|
||||
_applied_steering = false
|
||||
if applied_steering:
|
||||
applied_steering = false
|
||||
else:
|
||||
linear_velocity = GSAIUtils.clampedv3(GSAIUtils.to_vector3(current_position - _last_position), linear_speed_max)
|
||||
|
||||
if apply_linear_drag:
|
||||
linear_velocity = linear_velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage)
|
||||
|
||||
angular_velocity = clamp(_last_orientation - current_orientation, -angular_speed_max, angular_speed_max)
|
||||
angular_velocity = clamp(last_orientation - current_orientation, -angular_speed_max, angular_speed_max)
|
||||
|
||||
if apply_angular_drag:
|
||||
angular_velocity = lerp(angular_velocity, 0, angular_drag_percentage)
|
||||
|
||||
_last_position = current_position
|
||||
_last_orientation = current_orientation
|
||||
last_orientation = current_orientation
|
||||
|
@ -31,7 +31,7 @@ func _body_ready() -> void:
|
||||
# Moves the agent's `body` by target `acceleration`.
|
||||
# @tags - virtual
|
||||
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void:
|
||||
_applied_steering = true
|
||||
applied_steering = true
|
||||
if movement_type == MovementType.COLLIDE:
|
||||
_apply_collide_steering(acceleration.linear, delta)
|
||||
elif movement_type == MovementType.SLIDE:
|
||||
@ -115,10 +115,10 @@ func _set_body(value: KinematicBody) -> void:
|
||||
_body_ref = weakref(value)
|
||||
|
||||
_last_position = value.transform.origin
|
||||
_last_orientation = value.rotation.y
|
||||
last_orientation = value.rotation.y
|
||||
|
||||
position = _last_position
|
||||
orientation = _last_orientation
|
||||
orientation = last_orientation
|
||||
|
||||
if !had_body:
|
||||
if !body.is_inside_tree():
|
||||
@ -142,18 +142,18 @@ func _on_SceneTree_physics_frame() -> void:
|
||||
orientation = current_orientation
|
||||
|
||||
if calculate_velocities:
|
||||
if _applied_steering:
|
||||
_applied_steering = false
|
||||
if applied_steering:
|
||||
applied_steering = false
|
||||
else:
|
||||
linear_velocity = GSAIUtils.clampedv3(current_position - _last_position, linear_speed_max)
|
||||
|
||||
if apply_linear_drag:
|
||||
linear_velocity = linear_velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage)
|
||||
|
||||
angular_velocity = clamp(_last_orientation - current_orientation,-angular_speed_max,angular_speed_max)
|
||||
angular_velocity = clamp(last_orientation - current_orientation,-angular_speed_max,angular_speed_max)
|
||||
|
||||
if apply_angular_drag:
|
||||
angular_velocity = lerp(angular_velocity, 0, angular_drag_percentage)
|
||||
|
||||
_last_position = current_position
|
||||
_last_orientation = current_orientation
|
||||
last_orientation = current_orientation
|
||||
|
@ -23,7 +23,7 @@ func _apply_steering(acceleration : GSAITargetAcceleration, _delta : float) -> v
|
||||
if not _body:
|
||||
return
|
||||
|
||||
_applied_steering = true
|
||||
applied_steering = true
|
||||
_body.apply_central_impulse(GSAIUtils.to_vector2(acceleration.linear))
|
||||
_body.apply_torque_impulse(acceleration.angular)
|
||||
if calculate_velocities:
|
||||
@ -41,10 +41,10 @@ func _set_body(value: RigidBody2D) -> void:
|
||||
_body_ref = weakref(value)
|
||||
|
||||
_last_position = value.global_position
|
||||
_last_orientation = value.rotation
|
||||
last_orientation = value.rotation
|
||||
|
||||
position = GSAIUtils.to_vector3(_last_position)
|
||||
orientation = _last_orientation
|
||||
orientation = last_orientation
|
||||
|
||||
if !had_body:
|
||||
if !body.is_inside_tree():
|
||||
@ -68,8 +68,8 @@ func _on_SceneTree_frame() -> void:
|
||||
orientation = current_orientation
|
||||
|
||||
if calculate_velocities:
|
||||
if _applied_steering:
|
||||
_applied_steering = false
|
||||
if applied_steering:
|
||||
applied_steering = false
|
||||
else:
|
||||
linear_velocity = GSAIUtils.to_vector3(_body.linear_velocity)
|
||||
angular_velocity = _body.angular_velocity
|
||||
|
@ -22,7 +22,7 @@ func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> voi
|
||||
if !_body:
|
||||
return
|
||||
|
||||
_applied_steering = true
|
||||
applied_steering = true
|
||||
_body.apply_central_impulse(acceleration.linear)
|
||||
_body.apply_torque_impulse(Vector3.UP * acceleration.angular)
|
||||
if calculate_velocities:
|
||||
@ -40,10 +40,10 @@ func _set_body(value: RigidBody) -> void:
|
||||
_body_ref = weakref(value)
|
||||
|
||||
_last_position = value.transform.origin
|
||||
_last_orientation = value.rotation.y
|
||||
last_orientation = value.rotation.y
|
||||
|
||||
position = _last_position
|
||||
orientation = _last_orientation
|
||||
orientation = last_orientation
|
||||
|
||||
if !had_body:
|
||||
if !body.is_inside_tree():
|
||||
@ -66,8 +66,8 @@ func _on_SceneTree_frame() -> void:
|
||||
orientation = current_orientation
|
||||
|
||||
if calculate_velocities:
|
||||
if _applied_steering:
|
||||
_applied_steering = false
|
||||
if applied_steering:
|
||||
applied_steering = false
|
||||
else:
|
||||
linear_velocity = _body.linear_velocity
|
||||
angular_velocity = _body.angular_velocity.y
|
||||
|
@ -29,8 +29,8 @@ var linear_drag_percentage : float = 0.0
|
||||
# Does not apply to `RigidBody` and `RigidBody2D` nodes.
|
||||
var angular_drag_percentage : float = 0.0
|
||||
|
||||
var _last_orientation : float = 0.0
|
||||
var _applied_steering : bool = false
|
||||
var last_orientation : float = 0.0
|
||||
var applied_steering : bool = false
|
||||
|
||||
func apply_steering(_acceleration : GSAITargetAcceleration, _delta : float) -> void:
|
||||
call("_apply_steering", _acceleration, _delta)
|
||||
|
@ -4,14 +4,13 @@
|
||||
class_name GSAIPriority
|
||||
extends GSAISteeringBehavior
|
||||
|
||||
var _behaviors : Array = Array()
|
||||
|
||||
# The index of the last behavior the container prioritized.
|
||||
var _last_selected_index : int = 0
|
||||
# If a behavior's acceleration is lower than this threshold, the container
|
||||
# considers it has an acceleration of zero.
|
||||
var zero_threshold : float = 0.0
|
||||
|
||||
# The index of the last behavior the container prioritized.
|
||||
var _last_selected_index : int = 0
|
||||
var _behaviors : Array = Array()
|
||||
|
||||
# Appends a steering behavior as a child of this container.
|
||||
func add_behavior(behavior: GSAISteeringBehavior) -> void:
|
||||
|
@ -58,7 +58,7 @@ func calculate_distance(agent_current_position : Vector3) -> float:
|
||||
|
||||
for i in range(_segments.size()):
|
||||
var segment: GSAISegment = _segments[i]
|
||||
var distance_squared : float = calculate_point_segment_distance_squared(segment.begin, segment.end, agent_current_position)
|
||||
var distance_squared : float = _calculate_point_segment_distance_squared(segment.begin, segment.end, agent_current_position)
|
||||
|
||||
if distance_squared < smallest_distance_squared:
|
||||
_nearest_point_on_path = _nearest_point_on_segment
|
||||
@ -105,7 +105,7 @@ func get_end_point() -> Vector3:
|
||||
return _segments.back().end
|
||||
|
||||
|
||||
func calculate_point_segment_distance_squared(start: Vector3, end: Vector3, position: Vector3) -> float:
|
||||
func _calculate_point_segment_distance_squared(start: Vector3, end: Vector3, position: Vector3) -> float:
|
||||
_nearest_point_on_segment = start
|
||||
var start_end : Vector3 = end - start
|
||||
var start_end_length_squared : float = start_end.length_squared()
|
||||
|
Loading…
Reference in New Issue
Block a user