Godot Version
4.3
Question
Sorry this is only my 3rd (?) week of using Godot, so I might be missing something obvious here. I am getting a weird bug where my button presses going diagonally up the screen simply don’t register and I have no idea why? When the player character pressed a fire button it’s supposed to shoot out a projectile in the direction the arrow is facing (the arrow is there simply for testing so I know what it’s supposed to be doing). It seems to work find in all directions except up-left and up-right while in motion. If I stop moving then it’ll work fine.
https://youtu.be/qE877uvq4Wg - here’s some footage of the bug.
It won’t even run this line of code when moving diagonally up.
Player code (sorry, it needs cleaning up a bit now):
extends CharacterBody2D
@onready var animated_sprite_2d = $AnimatedSprite2D
@onready var camera_2d_midpoint: Camera2D = $"../Camera2D_midpoint"
#@onready var camera_2d_midpoint: Camera2D = $"../Camera2D_midpoint"
@onready var player_mingus: CharacterBody2D = $"../Player_Mingus"
@onready var speach_bubble: Sprite2D = $"SpeachBubble-sheet"
@onready var label_speach: Label = $"SpeachBubble-sheet/Label_speach_blight"
@onready var speach_timer: Timer = $Speach_Timer_Blight
@onready var attack_spawner: Node2D = $attack_spawner
var attack_spawners
const speed = 55
const friction = 0.2
const acceleration = 0.1
const MAX_DISTANCE = 150
var distance_to_mingus
var direction_to_mingus
var stop_right: bool
var stop_left: bool
var stop_up: bool
var stop_down: bool
# Speaking
var calling_lines = ["Mingus!?!","Mingus!
You are too far away!","Come back here, Mingus!", "Over here,
Mingus!", "Mingus?!", "Mingus, you are too far away!", "Come over here!", "Come here!", "Over here!", "We are going to lose each other!"]
var speaking: bool
func _ready() -> void:
speach_bubble.visible = false
label_speach.visible = false
attack_spawners = get_child(0)
func speaking_text_bubble(text_to_speak: String, time_speak: int):
speaking = true
speach_bubble.visible = true
label_speach.visible = true
label_speach.text = text_to_speak
speach_timer.start(time_speak)
func _on_speach_timer_blight_timeout() -> void:
speaking = false
speach_bubble.visible = false
label_speach.visible = false
func midpoint_distance():
distance_to_mingus = position.distance_to(player_mingus.position)
# direction_to generates two floats, Vector2, depending on where Blight is to Mingus
# 1st number = X float, Blight Left (negative) to Blight Right (positive)
# 2nd number = Y float, Blight Above (negative) to Blight Below (positive)
direction_to_mingus = position.direction_to(player_mingus.position)
if distance_to_mingus >= MAX_DISTANCE:
if !speaking:
var shout_come_here = calling_lines.pick_random()
speaking_text_bubble(shout_come_here, 3)
if direction_to_mingus.x < 0:
# if X = negative stop right moving.
stop_left = false
stop_right = true
elif direction_to_mingus.x > 0:
# if X = positive stop left moving.
stop_right = false
stop_left = true
if direction_to_mingus.y < 0:
# if Y = negative stop down moving.
stop_up = false
stop_down = true
elif direction_to_mingus.y > 0:
# if Y = negative stop up moving.
stop_down = false
stop_up = true
else:
stop_down = false
stop_up = false
stop_right = false
stop_left = false
func get_input():
var vertical # var vertical = Input.get_axis("ming_up", "ming_down")
var horizontal # var horizontal = Input.get_axis("ming_left", "ming_right")
if !stop_down and !stop_up:
vertical = Input.get_axis("bli_up", "bli_down")
else:
if stop_down:
vertical = Input.get_axis("bli_up", "off")
elif stop_up:
vertical = Input.get_axis("off", "bli_down")
if !stop_left and !stop_right:
horizontal = Input.get_axis("bli_left", "bli_right")
else:
if stop_left:
horizontal = Input.get_axis("off", "bli_right")
elif stop_right:
horizontal = Input.get_axis("bli_left", "off")
return Vector2(horizontal, vertical)
func animations(directions):
if directions.y != 0:
if directions.y < 0:
animated_sprite_2d.play("walk_up_blight")
elif directions.y > 0:
animated_sprite_2d.play("walk_down_blight")
if directions.x != 0:
if directions.x < 0:
animated_sprite_2d.set_flip_h(true)
animated_sprite_2d.play("walk_side_blight")
elif directions.x > 0:
animated_sprite_2d.play("walk_side_blight")
animated_sprite_2d.set_flip_h(false)
else:
animated_sprite_2d.set_flip_h(false)
func _process(_delta):
midpoint_distance()
func _physics_process(_delta):
if Input.is_action_pressed("bli_attack1"):
print("attack1 input button pressed <<<<<<<<<<<<")
attack_spawners.attack("bullet1",1)
if Input.is_action_pressed("bli_attack2"):
attack_spawners.attack("bullet2",2)
if Input.is_action_pressed("bli_attack3"):
attack_spawners.attack("bullet1",3)
if Input.is_action_pressed("bli_attack4"):
attack_spawners.attack("bullet2",4)
var direction:Vector2 = get_input()
if direction.length() > 0:
velocity = velocity.lerp(direction.normalized() * speed, acceleration)
var rot = direction.angle()
attack_spawner.set_rotation(rot)
animations(direction)
#float joystickAngle = Input.GetVector("aimLeft", "aimRight", "aimUp", "aimDown").Angle();
#Rotation = joystickAngle;
else:
velocity = velocity.lerp(Vector2.ZERO, friction)
animated_sprite_2d.set_flip_h(false)
animated_sprite_2d.play("idle_blight")
move_and_slide()
Thank you for any and all help. I feel like I must be missing something obvious.