How do i make something move? (Solved)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KND2501

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

:bust_in_silhouette: Reply From: KoBeWi

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

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

Replace move_x and move_y 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.

Thanx, i also found.

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

Can you tell me what the difference is?

KND2501 | 2018-03-08 19:33

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).

KoBeWi | 2018-03-09 00:09

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.

KND2501 | 2018-03-09 20:20

Thank you for sharing this very helpful for me

ToniStewart | 2021-04-12 15:12