2023-02-07 13:22:31 -07:00
|
|
|
extends CharacterBody3D
|
|
|
|
|
|
|
|
|
2023-02-09 13:10:25 -07:00
|
|
|
const SPEED = 3.0
|
2023-02-07 13:22:31 -07:00
|
|
|
const JUMP_VELOCITY = 4.5
|
|
|
|
|
|
|
|
var bullettimer = 50
|
|
|
|
var bulletshot = false
|
|
|
|
var bulletrandom
|
|
|
|
|
|
|
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
|
|
|
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
|
|
|
|
2023-02-23 10:19:37 -07:00
|
|
|
var player
|
2023-02-07 13:22:31 -07:00
|
|
|
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
2023-02-23 10:19:37 -07:00
|
|
|
if Global.selfTeddy:
|
|
|
|
player = get_node(Global.selfTeddy)
|
2023-02-07 13:22:31 -07:00
|
|
|
# Add the gravity.
|
|
|
|
if not is_on_floor():
|
|
|
|
velocity.y -= gravity * delta
|
|
|
|
|
|
|
|
|
|
|
|
if player and Global.playerAlive:
|
|
|
|
bullettimer = bullettimer - 10 * delta
|
|
|
|
if bullettimer < 0 and bulletshot == false:
|
|
|
|
bulletshot = true
|
|
|
|
var b = Bullet.instantiate()
|
|
|
|
owner.add_child(b)
|
|
|
|
b.transform = $CollisionShape3D/Neck/BulletGenerator.global_transform
|
|
|
|
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
|
2023-02-22 21:31:22 -07:00
|
|
|
$sound.stream = load("res://sounds/pistol_shoot.wav")
|
|
|
|
$sound.play()
|
2023-02-07 13:22:31 -07:00
|
|
|
elif bulletshot == true:
|
|
|
|
bulletshot = false
|
|
|
|
bulletrandom = randf_range(1.0, 50.0)
|
|
|
|
bullettimer = bulletrandom
|
2023-02-09 13:10:25 -07:00
|
|
|
velocity = (player.transform.origin - transform.origin).normalized() * SPEED
|
|
|
|
$CollisionShape3D.look_at(Vector3(player.global_transform.origin.x, global_transform.origin.y, player.global_transform.origin.z), Vector3(0,1,0))
|
2023-02-07 13:22:31 -07:00
|
|
|
move_and_slide()
|