It worked, thank you Altria!
undefined
Muhammad Aregbesola
@Muhammad Aregbesola
Posts
-
-
This is my code now:
extends KinematicBody2D # Declare member variables here. Examples: # var a = 2 # var b = "text" # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): # pass export (int) var run_speed = 50 export (int) var jump_speed = -400 export (int) var gravity = 1200 var velocity = Vector2() var jumping = false var direction = -1 func get_input(): if direction == 1: $Sprite.flip_h = 1 velocity.x += run_speed if direction == -1: $Sprite.flip_h = 0 velocity.x -= run_speed func _physics_process(delta): get_input() if is_on_wall(): direction *= -1 velocity = move_and_slide(velocity, Vector2(0, -1))
And it keeps turning around but doesn't go anywhere
-
My problem is pretty simple. When I start the game, the enemy starts moving left, facing left like it's supposed to. It hits the wall and then turned around, facing right and moving right. It hits the wall, and then it stops. Here is my code:
extends KinematicBody2D export (int) var run_speed = 50 export (int) var jump_speed = -400 export (int) var gravity = 1200 var velocity = Vector2() var jumping = false var direction = 0 func get_input(): if direction == 1: $Sprite.flip_h = 1 velocity.x += run_speed if direction == -1: $Sprite.flip_h = 0 velocity.x -= run_speed if is_on_wall() and direction == 1: velocity.x = 0 direction = -1 velocity.x -= run_speed if is_on_wall() and direction == -1: velocity.x = 0 direction = 1 velocity.x += run_speed func _physics_process(delta): get_input() velocity = move_and_slide(velocity, Vector2(0, -1))
Please help me I have tried for two hours and don't know what to do
Enemy not rebounding off of walls multiple times.
Enemy not rebounding off of walls multiple times.
Enemy not rebounding off of walls multiple times.