i was testing the game and my player was not moving,but it was before,and i can even control the enemy.

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

The player script:

extends KinematicBody2D

var motion = Vector2()
export(int) var SPEED = 200

func _physics_process(delta):
		motion.x = -SPEED
		motion.x = SPEED
		motion.x = 0
	motion = move_and_slide(motion)

func dash():
	SPEED = 500
	$Collision.disabled = true

func _on_DashTimer_timeout():
	SPEED = 200
	$Collision.disabled = false

The Enemy Script:

extends StaticBody2D
var SPEED = 4
var screen
var initial_position
var x_final
var y_final
export var final_position = Vector2.ZERO

func _ready():
	screen = get_viewport().size
	initial_position = Vector2(position.x, position.y)
	if(final_position == Vector2.ZERO):
		final_position = Vector2(initial_position.x + randi()%100, initial_position.y + randi()%100)
	x_final = final_position.x
	y_final = final_position.y

func _process(delta):
	if(rotation_degrees != -360):
		rotation_degrees -= 10
		while(rotation_degrees != 360):
			rotation_degrees += 10

	if(x_final != position.x):
		if(x_final < position.x):
			position.x -= SPEED
			position.x += SPEED
	if(y_final != position.y):
		if(y_final < position.y):
			position.y -= SPEED
			position.y += SPEED

I’m not 100% sure on this, which is why I’m commenting not answering, but is it possible that initially defining motion without values is the root of the problem? (Try and define it as Vector2(0, 0)/Vector2.ZERO (same thing))

RedBlueCarrots | 2020-05-28 03:47

is it possible that initially defining motion without values is the root of the problem?

No, a vector’s x- and y-properties default to zero:
Vector2() == Vector2(0, 0) == Vector2.ZERO

my player was not moving

I cannot reproduce that. Your player-code works fine as is.

i can even control the enemy.

You mean, instead of the player you move the enemy? Again: I cannot reproduce that. Your enemy-script works as well and does not interfere with the player-script.

njamster | 2020-05-28 12:26

Are you positive the scripts are allocated correctly

Ogeeice | 2020-05-29 18:03

I also noticed your enemy is a staticbody type,don’t you think it would be better to use a kinematic or rigidbody instead

Ogeeice | 2020-05-29 18:05