4.2
Much like the topic says, pressing D and then A in rapid succession while airborne turns the character into a missile. Here’s my code:
extends CharacterBody2D
var is_in_air = false
var move_modifier = 1
var player_color = 0
signal jump
@onready var jump_signal = connect("jump", _on_jump)
func _ready():
pass
func _physics_process(_delta):
#handles movement
velocity = Vector2(0,0)
if is_in_air == true:
move_modifier == move_modifier * 0.5
else:
move_modifier != move_modifier
if Input.is_action_pressed("right"):
velocity.x = 300 * move_modifier
if Input.is_action_pressed("left"):
velocity.x = -300 * move_modifier
if Input.is_action_just_pressed("jump") and is_on_floor() or is_on_wall():
emit_signal("jump")
if is_on_floor() == false:
velocity.y += 75
is_in_air == true
move_and_slide()
#handles color
if Input.is_action_just_pressed("blue_swap"):
var blue = load("res://player-sprite-blue.png")
$Sprite2D.texture = blue
player_color = 2
if Input.is_action_just_pressed("red_swap"):
var red = load("res://player-sprite-red.png")
$Sprite2D.texture = red
player_color = 0
if Input.is_action_just_pressed("green_swap"):
var green = load("res://player-sprite-green.png")
$Sprite2D.texture = green
player_color = 1
func _on_jump():
$"..".apply_impulse(Vector2(0,-1200))
Edit: I did some testing, and it can happen in either direction if there’s even a slight change in elevation.