blob: 24b93f90fce0b400dcd7685d35d6215dc22dd655 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
extends KinematicBody
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export(NodePath) var parent_vehicle = null
#onready var nav_agent : NavigationAgent = get_node("NavigationAgent")
var parent_vehicle_nav = null
var destination = Vector3.ZERO
var closest_point = Vector3.ZERO
var direction = Vector3.ZERO
var path = null
var pathfinding = false
const speed = 5
var velocity = Vector3.ZERO
# Called when the node enters the scene tree for the first time.
func _ready():
if parent_vehicle != null:
parent_vehicle = get_node(parent_vehicle)
parent_vehicle_nav = parent_vehicle.get_node("Navigation")
#nav_agent.set_navigation(parent_vehicle_nav)
func update_destination(new_dest):
pass#nav_agent.set_target_location(new_dest)
func move(delta):
var target = Vector3.ZERO#nav_agent.get_next_location()
var direction : Vector3 = (target - global_transform.origin).normalized() * speed
velocity.y -= 9.8*delta
velocity.x = direction.normalized().x*speed
velocity.z = direction.normalized().z*speed
#nav_agent.set_velocity(Vector3(velocity.x,0,velocity.z))
velocity = move_and_slide(velocity, Vector3.UP, true, 4, 0.785, false)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
move(delta)
|