Godot Version
4.3
Question
So im trying to make an AI for an Avatar game im making about earthbending, how can i make my animatable body “Rock” move towards the player last position and not stop moving or change directions?
4.3
So im trying to make an AI for an Avatar game im making about earthbending, how can i make my animatable body “Rock” move towards the player last position and not stop moving or change directions?
1 - I created a “Projectile” scene in my game, basically this node move their parent to a direction every frame (i prefer to create a secondary-base scene because if you have multiple projectiles you can prevent repetition)
extends Node3D
class_name Projectile
@export var speed = 100
var direction : Vector3
func _process(delta: float) -> void:
if direction:
get_parent().position += direction * delta * speed
2 - add this node as a child to your “Rock”
3 - instanciate a Rock in the place you want (when pressing a button, on some event/signal etc) and set the direction to player
@onready var rock = preload("res://path_to_rock.tscn")
func _my_func () :
var rock = rock.instantiate()
#start position based on this node position
rock.position = position
#start direction based on this node position
projetil.find_child("Projetil").direction = global_position.direction_to(player.global_position)
add_child(rock)
Probably you will have to adapt something to your code, but i hope that can help