Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TheAsker |
I’m working on a 2d platformer. You can shoot projectiles in it. When the player is on a wall I want the player to shoot the projectiles in the opposite direction than normal, but I can’t get it to work right. Can you help me?
This is the code
extends KinematicBody2D
var motion = Vector2()
var airjump = 0.2
var airtime = 0.2
var cutjumpheight = 0
var aim = 1
var whereaim = -1
var gravity = 60
const WJX = 100
const MOE = 0.2
const CTIME = 0.2
const SPEED = 300
const WALLJUMPHEIGHT = -1125
const JUMPHEIGHT = -750
const UP = Vector2(0,-1)
const LIGHTING = preload("res://LightingAttack.tscn")
#move right and left whenthe arrow keys are presed
func _physics_process(delta):
#explains self
motion.y += gravity
if Input.is_action_pressed("ui_right"):
motion.x = SPEED
if sign($Position2D.position.x) == -1:
$Position2D.position.x *= -1
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED
if sign($Position2D.position.x) == 1:
$Position2D.position.x *= -1
else:
motion.x = 0
# this reverses the position the lighting comes out when on a wall unless the player is on the floor
if is_on_wall():
$Position2D.position.x *= whereaim
#Timer to dimtermine if the player inputed the jump button recently
airjump -= get_process_delta_time()
if Input.is_action_just_pressed("ui_up"):
airjump = CTIME
#Timer to see if the player was on the floor or wall recently
airtime -= get_process_delta_time()
if is_on_floor():
airtime = MOE
#slows decent if player is on a wall
if is_on_wall() && motion.y > 0 &&! is_on_floor():
gravity = 30
whereaim = 1
else:
gravity = 60
whereaim = -1
#Tells the game to jump
if airtime > 0 && airjump > 0:
motion.y = JUMPHEIGHT
if Input.is_action_pressed("ui_up"):
cutjumpheight -= 0
if cutjumpheight > 0:
cutjumpheight = 0
if Input.is_action_just_released("ui_up"):
motion.y += cutjumpheight
if is_on_wall() && Input.is_action_just_pressed("ui_up"):
if sign($Position2D.position.x) == 1:
motion.y = WALLJUMPHEIGHT
motion.x = WJX
elif sign ($Position2D.position.x) == -1:
motion.y = WALLJUMPHEIGHT
motion.x == -WJX
motion = move_and_slide(motion, UP)
pass
if Input.is_action_just_pressed("ui_focus_next"):
var lighting = LIGHTING.instance()
if sign($Position2D.position.x) == 1:
lighting.set_lighting_direction(1)
else:
lighting.set_lighting_direction(-1)
get_parent().add_child(lighting)
lighting.position = $Position2D.global_position
Thanks!