Godot 3d tutorial: https://docs.godotengine.org/en/stable/getting_started/first_3d_game/07.killing_player.html
This commit is contained in:
27
Mob.gd
Normal file
27
Mob.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
@export var min_speed = 10
|
||||
@export var max_speed = 18
|
||||
|
||||
signal squashed
|
||||
|
||||
func _physics_process(delta):
|
||||
move_and_slide()
|
||||
|
||||
func initialize(start_position, player_position):
|
||||
# Look to the player
|
||||
look_at_from_position(start_position, player_position, Vector3.UP)
|
||||
# But rotate a little bit
|
||||
rotate_y(randf_range(-PI / 4, PI / 4))
|
||||
# Set random speed
|
||||
var random_speed = randi_range(min_speed, max_speed)
|
||||
# Apply the velocity
|
||||
velocity = Vector3.FORWARD * random_speed
|
||||
velocity = velocity.rotated(Vector3.UP, rotation.y)
|
||||
|
||||
func squash():
|
||||
squashed.emit()
|
||||
queue_free()
|
||||
|
||||
func _on_visibility_notifier_screen_exited():
|
||||
queue_free()
|
||||
Reference in New Issue
Block a user