The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I want that the x value of a region rect of a sprite is set to the x position of a KinematicBody2d divided by 10 plus 52 and the same with the y value of the region rect.

I tried this:

get_node("Sprite").region_rect = 
Rect2(get_node("KinematicBody2d").position.x / 10 + 52, 
      get_node("KinematicBody2d").position.y / 10 + 52)
#In the real code this is all in one row

But I got this error:

Invalid type in 'Rect2' constructor. Cannot convert argument 1 from Nil to Vector2.

How can I fix that?
Thanks for answers.

in Engine by (378 points)

2 Answers

+2 votes
Best answer

Hi, a Rect2 has two Vector2s, you've only got one.
So you either need to specify another Vector2 for the size, or just set the sprites region_rect position

by (2,035 points)
selected by
+1 vote

I think the syntax is this:

Rect2 ( float x, float y, float width, float height )


Rect2 ( Vector2 position, Vector2 size )

by (188 points)
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.