- Edited
So I've been beating my head against this for a while. I used to do this in godot 3.x but I'm having a lot of trouble with it now.
I'm trying to get the velocity of another CharacterBody2D, so I needed to reference the node in order to get it's properties, right?
It took me a while to even print the node that I wanted to get, but now that I have it, using "Player.velocity" doesn't work.
here's the code:
extends CharacterBody2D
class_name Enemy
@onready var player = get_node("%Player")
var playerVel = player.velocity
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
@export_range(0.0, 1.0) var friction = 0.15
@export_range(0.0, 1.0) var acceleration = 0.2
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _ready():
print(playerVel)
#smash as in Super Smash Bros
func smash():
#velocity = playerVel * -1
pass
#Death
func death():
queue_free()
print("enemy")