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

Input.get_vector() does not respect Input.action_press() #62593

Closed
WolfgangSenff opened this issue Jul 1, 2022 · 6 comments
Closed

Input.get_vector() does not respect Input.action_press() #62593

WolfgangSenff opened this issue Jul 1, 2022 · 6 comments

Comments

@WolfgangSenff
Copy link
Contributor

WolfgangSenff commented Jul 1, 2022

Godot version

3.5.rc5

System information

Windows 11

Issue description

Working on a tutorial using simulated input, I noticed that if you use Input.action_press() to simulate input, it will not be picked up, no matter what values you use, in Input.get_vector(). The reason appears to be that at some point or another, the raw_strength of the simulated action is set to 0, and that's what get_vector() uses. The action_strength has the correct value, but because it uses the raw_strength, get_vector() returns Vector2(). This might be intentional, but I'm not sure. I have attached a repro project - it's fairly big, didn't bother to create a new one, just the one I'll be using for my tutorial.

I suppose for some reason this might be on purpose, but it seems like in other parts of the codebase, the raw_strength is actually the same as the normal strength, so it's confusing to me why this would differ, especially if I set the strength directly in my Input.action_press() call (it is not set that way currently, but it's easy enough to manipulate).

In the repro project below, it is possible to work around this by manually building the vector, but I don't really see why I shouldn't be able to use Input.get_vector().

Steps to reproduce

  1. Download the repro project
  2. Run the game
  3. On the left, drag the button down by tapping on the screen and moving said button down
  4. Observe the printed values

Quick edited note:
You can repro the desired behavior by using the arrows or WASD to generate the values I would expect from Input.get_vector().

Minimal reproduction project

UnidentifiedFlyingAwesome.zip

@Calinou
Copy link
Member

Calinou commented Jul 1, 2022

cc @aaronfranke

@aaronfranke
Copy link
Member

Do we want raw strength to contain simulated input? We'd need to do one of these three things:

@WolfgangSenff
Copy link
Contributor Author

I'm not sure if it's actually a useful suggestion, but what about a set_vector function that's publicly available? Could simulate it that way, and it could do it in such a way that get_vector just works.

@whiteshampoo
Copy link

whiteshampoo commented Jul 5, 2022

I made this as a quick&dirty hotfix:

func Input_get_vector(nx : String, px : String, ny : String, py : String, deadzone : float = -1.0) -> Vector2:
	var vector : Vector2 = Vector2.ZERO
	vector.x = Input.get_axis(nx, px)
	vector.y = Input.get_axis(ny, py)
	vector = vector.clamped(1.0)
	
	if is_equal_approx(deadzone, -1.0):
		deadzone = InputMap.action_get_deadzone(nx)
		deadzone += InputMap.action_get_deadzone(px)
		deadzone += InputMap.action_get_deadzone(ny)
		deadzone += InputMap.action_get_deadzone(py)
		deadzone /= 4.0
	deadzone = clamp(deadzone, 0.0, 1.0)
	
	return vector.normalized() * max((vector.length() - 1.0) * (1.0 / (1.0 - deadzone)) + 1.0, 0.0)

Should more or less work until this is fixed. Maybe someone will find this useful... (CC0)

@YeldhamDev
Copy link
Member

I would like to add that this bug also makes inputs from TouchScreenButtons be ignored.

@akien-mga
Copy link
Member

Fixed in 4.0 by #59911 and in 3.6 by #66480.

@akien-mga akien-mga modified the milestones: 4.0, 3.6 Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants