Godot Version
4.4
Question
i have been having a problem with the collisions after working it again and again now i understand why it doesn’t work but not how to fix it.
using other shapes for the collision makes weird stuff from just not working to making it fly into the sky
You have some screenshots of warnings, but I think you should post what the nodes you are using are and what the code is.
i can change it to a rigid body but that breaks the code
extends RigidBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
@export var D_P := 20
@export var max_Hp := 100
@export var attack_range := 1.5
var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")
@onready var navigation_agent_3d: NavigationAgent3D = $NavigationAgent3D
@onready var animation_player: AnimationPlayer = $AnimationPlayer
var player
var provoked := false
var relaxed := true
var agrro_range := 12.0
var Hp: int = max_Hp:
set(value):
Hp = value
if Hp <=0 :
queue_free()
provoked = true
func _ready() -> void:
player = get_tree().get_first_node_in_group("player")
if relaxed :
animation_player.play("idle")
func _process(delta: float) -> void:
if provoked:
navigation_agent_3d.target_position = player.global_position
func _physics_process(delta: float) -> void:
var next_position = navigation_agent_3d.get_next_path_position()
# Add the gravity.
if not is_on_floor():
velocity.y-= gravity * delta
var direction = global_position.direction_to(next_position)
var distance = global_position.distance_to(player.global_position)
if distance <= agrro_range:
provoked=true
if provoked:
if distance <= attack_range:
animation_player.play("attack")
if direction:
look_at_target(direction)
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
func look_at_target(direction: Vector3) -> void:
var adjused_direction = direction
adjused_direction.y = 0
look_at(global_position + adjused_direction, Vector3.UP, true)
func attack() -> void:
player.Hp -= D_P