0 votes

I just want one directional motion, no inputs. Just start and go.

in Engine by (103 points)
edited by

1 Answer

+1 vote
Best answer

Attach script to your object, which will look like this:

func _process(delta):
    position += Vector2(move_x, move_y)

Replace movex and movey with the speed you want to move (e.g. Vector2(1, 0) to go right). Since it's only 2 lines, you may make the script built-in.

by (141 points)
selected by

Thanx, i also found.

func _physics_process(delta):
move_and_collide(Vector2(-1, 0))

Can you tell me what the difference is?

With move_and_colide, the object will stop if it meets an obstacle. This works if you place a physics body in path of your moving object (e.g. StaticBody2D). With normal position movement like in my original answer, it will just move forward and ignore everything.

To use move_and_collide, your object needs to be of KinematicBody2D type (or normal KinematicBody, if you don't make 2D).

That's great to know. I'm just trying to figure out how stuff moves. There seems to be so many ways to do the same it's kinda confusing.

Thanx for clearing this up.

Thank you for sharing this very helpful for me

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 webmaster@godotengine.org with your username.