0 votes

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.setlinearvelocity(Vector2.RIGHT*SPEED)

func physicsprocess(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 onredEnemybodyentered(body):
if body.name == "Cake":
teleport()

Godot version 3.2.2
in Engine by (22 points)

1 Answer

0 votes

Nevermind, just realized that I had to use the setglobalposition() 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 setglobalposition() !

by (22 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.