Why does my game do this???

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

I am trying to make a game in whihc the player controls a character, and pushes enemies off the road; it is a 2d game. For some reason, the enemies start moving like CRAZY! I think it’s because the forces from the player are still applied onto them. I don’t know thow to fix this!

Here is the code for the enemies is this helps:

extends RigidBody2D

const SPEED = 100

func _ready():
teleport()

func teleport():
self.position.x = 0
self.position.y = randi()%100 +242
self.set_linear_velocity(Vector2.RIGHT*SPEED)

func _physics_process(_delta):
self.z_index = (position.y /10 ) as int
if (position.y > 342) or (position.y < 242) or (position.x < 0) or (position.x > 751):
teleport()

func _on_redEnemy_body_entered(body):
if body.name == “Cake”:
teleport()

:bust_in_silhouette: Reply From: EK1318

Nevermind, just realized that I had to use the set_global_position() function, not postion =… .

Local position - position of a node relative to its parent
Global position - position of a node on screen.

If, you want to change a position of a node, use set_global_position() !