0 votes

I want an animated sprite to change position and also want it's offset to change position when an input is received. I do know about the offset and position functions but i still don't understand how do i use them, can someone explain me

Godot version 3.4.2
in Engine by (30 points)

Depends where you are putting the script.

Lots of possibilities... here's the basics:


1 Answer

+2 votes

I believe what you are trying to do is

if Input.is_action_pressed("input"):
     position.x += 10
     # or offset.x += 10
     # you may also do position -= 10 to have it move left
     # if you want to have the Y axis change, write position.y

Or if you want to directly set the nodes position, write

position = Vector2(x, y)
# x and y should be written as integers, or other variables/constants
# Vector2() is the data type for coordinates, or directions

I hope that helped
If you meant changing the position from within the animation, I recommend using the "AnimationPlayer" node. You can find more about that in the documentation.

by (42 points)

that helped a lot, thanks

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.