Raycast direction upload while shot problem

Godot Version

4.4.1

Hello, everyone! I am having an issue with updating the direction of a raycast… I have a state machine, and I control the direction of the raycast from a GameManager (I did this after trying to update from several places and it didn’t work) in an AutoLoad. While I’m moving, everything works, but when I hold down the fire button, the Raycast works for all directions except for the top-left and bottom-right diagonals. I’ve attached the GameManager and Shot state scripts… if you need any more information, please ask. Thank you very much.

GameManager script

extends Node

var enemies: Array = []
var enemies_in_scene: int = 0

var player: Node = null
var input_vector
var shot_direction: String = ""


func _process(delta: float) -> void:
	enemies = get_tree().get_nodes_in_group("Enemies")

	input_vector = InputManager.move_vector
	
	if input_vector != Vector2.ZERO:
		player.shot_cast.target_position = input_vector * player.shot_distance

Shot Script

extends StateMachine


@export var shot_distance = 250

@onready var shot_cast: RayCast2D = $"../../ShotCast"

var shot_cast_col
var collision_point

signal impact

func reset_state():

	player.velocity = Vector2.ZERO	
	
func _ready() -> void:
	pass 

func _physics_process(delta: float) -> void:
	
	if player.current_state == "shot":		
			
		if shot_cast.is_colliding():
			shot_cast_col = shot_cast.get_collider()
			collision_point = shot_cast.get_collision_point()
			
			if shot_cast_col.is_in_group("Enviro"):
				if shot_cast_col.has_method("take_damage"):
					var damage_amount = 0 
					shot_cast_col.take_damage(damage_amount, collision_point)
			if shot_cast_col.is_in_group("Enemies"):
				if shot_cast_col.has_method("take_damage"):
					var damage_amount = 1
					shot_cast_col.take_damage(damage_amount, collision_point)
					


			
		if Input.is_action_just_released("shot") and player.velocity == Vector2.ZERO:
			player.change_state("idle")
		elif Input.is_action_just_released("shot") and player.velocity != Vector2.ZERO:
			player.change_state("move")

Sorry… InputManager.move_vector is calculated like this

move_vector.x = Input.get_axis("move_left", "move_right")
move_vector.y = Input.get_axis("move_up", "move_down")

Solved. I don’t know why, but when I ran the code by pressing the space bar, certain diagonals stopped working. I changed the key to Alt and everything works correctly. I don’t know what kind of conflict the space bar was creating. If anyone knows, I would appreciate the answer.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.