This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes
onready var swordHitbox = $HitboxPivot/SwordHitbox
func _ready():
 swordHitbox = Vector2.ZERO
swordHitbox.knockback_vector = input_vector
in Engine by (18 points)

So what are you trying to do with this code? We know it involves knocking back something. But what are the details about the nodes involved, such as the SwordHitbox node?

1 Answer

+1 vote
Best answer

The error code is telling you that you are incorrectly trying to access a member knockback_vector of a type Vector2. Indeed this is the case.

First, you assign swordHitbox with what appears to be a hitbox in the scene tree with the line of code:

onready var swordHitbox = $HitboxPivot/SwordHitbox

This seems correct. However, in your ready function, you override/erase the reference to a hitbox with an empty Vector2

swordHitbox = Vector2.ZERO

swordHitbox no longer references a hitbox object, it's now a Vector2. You proceed to access a member knockback_vector of this empty vector

swordHitbox.knockback_vector = input_vector

Either remove swordHitbox = Vector2.ZERO or rethink your logic, because you are using the swordHitbox variable to store different types of variables (a hitbox and Vector2), which is bad design and can quickly get messy

by (1,468 points)
selected by

Thank you very much!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.