Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | mister_why |
Hi !
I’m trying to make a platform game, and of course I need THE wall jump.
I tried that when the character touch a wall, he stops moving, and when I push the “ui_right” he goes right and he doesn’t stick to the wall, but it doesn’t work
Do you have an other way to do it ?
My code :
`
extends KinematicBody2D
const UP = Vector2(0,-1)
const GRAVITY = 20
const SPEED = 200
const JUMP_HEIGHT = - 550
var motion = Vector2()
var motion_2 = Vector2()
var wall = false
func _physics_process(delta):
#not is_on_wall() and wall == false
if wall == false:
GRAVITY = 20
motion_2.y -= GRAVITY
motion_2.x -= GRAVITY
motion.y += GRAVITY
if Input.is_action_pressed("ui_right"):
motion.x = SPEED
$AnimatedSprite.play("Run")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED
$AnimatedSprite.play("Run")
$AnimatedSprite.flip_h = true
elif Input.is_action_just_pressed("Dash"):
if $AnimatedSprite.flip_h == true:
move_local_x(-50)
elif $AnimatedSprite.flip_h == false:
move_local_x(50)
else :
motion.x = 0
$AnimatedSprite.play("Idle")
if is_on_floor():
print("floor")
if Input.is_action_just_pressed("ui_up"):
motion.y = JUMP_HEIGHT
if is_on_wall():
print("wall")
wall = true
# motion.x = 0
# motion.y = 0
# GRAVITY = 0
# $AnimatedSprite.play("Idle")
if Input.is_action_pressed("ui_right"):
print("right")
wall = false`