Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GodotUser73 |
I’m having an issue in trying to implement double jump into my game. The issue I’m having is that when the player character jumps into a wall, the player character glides up the wall instead of just jumping off the wall. Why is this happening, and how can this be fixed?
This is my code for the player character:
extends KinematicBody2D
const jumpforce = -600
const maxspeed = 2048
var acceleration = 4
var gravity = 0
var velocity = Vector2(0,0)
onready var LeftRayCast = $LeftRayCast
onready var RightRayCast = $RightRayCast
# This function runs the loop that keeps the character running
func _physics_process(delta):
run()
jump()
friction()
gravity()
#Moves the ball
velocity = move_and_slide(velocity, Vector2.UP)
func run():
if Input.is_action_pressed("right") and not is_on_wall():# Move right
if velocity.x < 0:
velocity.x += acceleration * 2
else:
velocity.x += acceleration
if Input.is_action_pressed("left") and not is_on_wall():# Move left
if velocity.x > 0:
velocity.x -= acceleration * 2
else:
velocity.x -= acceleration
func jump():
if Input.is_action_pressed("up"):# Jump
if is_on_floor():# Normal Jump
velocity.y += jumpforce
elif not is_on_floor() and on_left_wall():# Left wall jump
velocity.y = jumpforce
velocity.x = jumpforce/2
elif not is_on_floor() and on_right_wall():# Right wall jump
velocity.y = jumpforce
velocity.x = -jumpforce/2
#elif is_on_wall():# Wall Jump
# if velocity.x > 0 and Input.is_action_pressed("right") and not Input.is_action_pressed("left"):
# velocity.y = jumpforce
# velocity.x = jumpforce/2
# if velocity.x < 0 and Input.is_action_pressed("left") and not Input.is_action_pressed("right"):
# velocity.y = jumpforce
# velocity.x = -jumpforce/2
func on_left_wall():
return $LeftRayCast.is_colliding() and Input.is_action_pressed("left")
func on_right_wall():
return $RightRayCast.is_colliding() and Input.is_action_pressed("right")
func gravity():
if is_on_floor():
if Input.is_action_pressed("down"):# Slide down a slope
gravity = 30
else:
gravity = 5
else:
gravity = 20
velocity.y = velocity.y + gravity
When it comes to the wall
Print(gravity) and see the result.
ramazan | 2022-01-31 08:57