![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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()