Improved control scheme
This commit is contained in:
@@ -26,6 +26,16 @@ func get_walk_speed() -> float:
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
var _path: Array
|
||||
|
||||
func walkto(target: Vector3, spd: float = 1.4):
|
||||
var cur = world.nav.get_closest_point(global_transform.origin)
|
||||
target = world.nav.get_closest_point(target)
|
||||
var path: PoolVector3Array = world.nav.get_simple_path(cur, target)
|
||||
_path = Array(path)
|
||||
set_walk_speed(spd)
|
||||
walk()
|
||||
|
||||
func _process(delta):
|
||||
orientation = global_transform
|
||||
orientation.origin = Vector3()
|
||||
@@ -41,6 +51,19 @@ func _process(delta):
|
||||
if is_in_group("master"):
|
||||
orientation *= controls.frame_tf
|
||||
controls.frame_tf = Transform()
|
||||
if _path && _path.size() > 0:
|
||||
while _path.size() > 0 && _path[0].distance_to(global_transform.origin) < 0.5:
|
||||
_path.pop_front()
|
||||
if _path.size() > 0:
|
||||
var next: Vector3 = _path[0]
|
||||
var direction: Vector3 = (next - global_transform.origin).normalized()
|
||||
var actual_direction: Vector3 = -global_transform.basis[2]
|
||||
var angle: float = Vector2(actual_direction.x, actual_direction.z).angle_to(Vector2(direction.x, direction.z))
|
||||
var tf_turn = Transform(Quat(Vector3(0, 1, 0), -angle * delta))
|
||||
orientation *= tf_turn
|
||||
if !_path || _path.size() == 0:
|
||||
idle()
|
||||
|
||||
orientation.origin = Vector3()
|
||||
orientation = orientation.orthonormalized()
|
||||
global_transform.basis = orientation.basis
|
||||
|
||||
Reference in New Issue
Block a user