0 votes

I keep getting the error message, 'Can't get index "width" on base "Vector2"' from the following code:

func goinitposition():
var initposition = Vector2()
position.x = getviewportrect().size.width + PIPEWIDTH/2
position.y = randrange(0+OFFSETY, getviewportrect().size.height-GROUNDHEIGHT-OFFSETY)

Is there something I am missing or another way to code this?

additional information:

I've been following a four year old Flappy Bird tutorial and so far there have been issues changing some code to function in 3.2, so this might be a similar case. The link to the video is here Flappy Bird Godot Engine Tutorial and the code is implemented at the time 35:39

in Engine by (15 points)

1 Answer

+1 vote
Best answer

The problem is here: get_viewport_rect().size.width and get_viewport_rect().size.height. get_viewport_rect().size has the properties x and y now, not width and height. So you should have this:

init_position.x = get_viewport_rect().size.x + PIPE_WIDTH/2
init_position.y = rand_range(0+OFFSET_Y, get_viewport_rect().size.y-GROUND+HEIGHT-OFFSET_Y)
by (8,152 points)
selected by

Thank you so much for the response and clear explanation, this has helped me immensely; cheers!

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.