Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant press space, up and left at the same time #93642

Open
N-suprem opened this issue Jun 26, 2024 · 2 comments
Open

Cant press space, up and left at the same time #93642

N-suprem opened this issue Jun 26, 2024 · 2 comments

Comments

@N-suprem
Copy link

Tested versions

Reproducible in 4.2.2 stable and 4.1 stable

System information

Windows 11 pro

Issue description

I made a code to move a character that use up down left right arrows and space. When I need to press up, left and space at the same time, the last pressed key does not work (usually left) (with the right one works fine). I tried different code and I get the same problem. I made a new project and did it from scratch and I get the same problem. I tried it in 3 computers and tried runing it in godot ans also as a exported project and I get the same problem in all cases. I changed space for other key and it works fine.

extends CharacterBody3D
@export var velMov : float = 500
@export var velMovCorr : float = 1000
@export var velMovTras : float = 200
@export var velGiro : float = PI
@export var velGiroCorr : float = 0.5*PI
@export var gravity : float = -800
var vel
var giro

func _process(delta: float) -> void:
	controles(delta)
	
func controles(delta):
	if Input.is_action_pressed("run"): 
		vel = velMovCorr
		giro = velGiroCorr
		print("run")
	else:
		vel = velMov
		giro = velGiro
	if Input.is_action_pressed("foward"):
		print("walk")
		velocity = get_global_transform().basis.z*-vel*delta
	elif Input.is_action_pressed("back"):
		velocity = get_global_transform().basis.z*velMovTras*delta
	else:
		velocity = Vector3.ZERO
	if Input.is_action_pressed("girarright"):
		rotation.y += -giro*delta
	if Input.is_action_pressed("girarleft"):
		print("left")
		rotation.y += giro*delta

	if not is_on_floor():
		velocity.y = gravity * delta
	move_and_slide()

I tried it on 4.1 stable and get the same isue. I wasnt able to try it in a 3.x version because I dont know how the code works there

Steps to reproduce

Just run the project and try whats described

Minimal reproduction project (MRP)

Prueba2 (2).zip

@TheLegoSensei
Copy link

so sometimes this is due to zones on the keyboard, some keyboards don't support certain button combinations. I just tested mine with this site and on my USB keyboard that I've had since Windows XP, then I also cannot press space, up, and left as you described. try it here, and this will inform you if it's your keyboard, or Godot.

@huwpascoe
Copy link

Unrelated to the issue, but worth mentioning:

bug

CharacterBody3D calculates delta velocity itself

velocity = vel * delta # bad, becomes vel*delta*delta in move_and_slide()
velocity = vel # ok

The speeds will need to be reduced accordingly from 500 to like 5.0

info

There are two functions, get_axis and get_vector that can help with getting directional input that can also handle analog joystick controllers, if you want to allow it.

var fwd = -get_global_transform().basis.z
var dz = Input.get_axis("back", "forward")
var dx = Input.get_axis("girarleft", "girarright")

if dz > 0.0:
  velocity = fwd * dz * vel
elif dz < 0.0:
  velocity = fwd * dz * velMovTras
else:
  velocity = Vector3.ZERO

rotation.y -= dx * giro * delta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants