So this may look a bit big. I’ve spent too many hours on it, and I’m finally looking for help!
The problem: When hitting jump during a dash (_is_dashing), the character moves up a bit, and starts a new dash. Dashing on the ground, and in the air both work. But the problem is somewhere here:
To be sure I understand the problem correctly, the character is moving up a bit when jump is pressed during the dash. However, they should not. You were very clear on what is happening, but not on what shouldn’t be. I’m assuming that’s what you meant, please clarify, if not. Your art looks amazing, by the way! Great looking game so far.
The problem lies in the following code:
#problem happens during this:
elif is_on_ floor) and _is_dashing:
# ...
_is_dashing = false # Not dashing any more, but still keep going...
velocity.y = _jump_velocity # Set the velocity upwards here!
# ...
I apologize in advance if this answer is stating the obvious and missing the problem… It seems like you put in a lot of work to understand the issue, so I’m worried I missed the point.
So at 2 seconds in is where the big problem is happening. She should exit the dash, and just straight up do her regular jump. But instead, she jumps up around 10 pixels for some reason, and then the dash starts over.
I have a feeling since dash (shift) is still being held, maybe it’s triggering the other dash instantly? Is there a way to ignore the shift input? Maybe set a short timer, or force it to release?
I understand better now! Thanks. Yes, the input is very likely the problem. How are you triggering these functions? Can you share?
If you’re using the shift key, then yes, it’s receiving input each frame. If you’re using an _input event, you may need to track with a variable whether it was pressed that frame. But there are better ways of getting button events that handle this.
That could be it! My current inputs look like this.
I’m reading though the link, I’m not sure it’s clicking yet for me. Assuming it’ll look something like this:
x if event is InputEventAction:
if event.button_index == dash_button and event.pressed:
#_character.dash()
print("Dash Pressed", event.position)
if event.button_index == dash_button_released and event.pressed:
#_character.stop_dash()
print("Dash Released")
Right! InputEvent.is_action_pressed() will be true for any frame during which the action is held down. To find out whether the action is just now pressed, there are two steps:
Find out if this event is the one you’re interested in by seeing if it’s an action of that type
Find out if, in this frame, that action has just been pressed.
func _is_action_just_pressed(event : InputEvent, name:String) -> bool:
if not event.is_action(name):
return false # Not interested in this event
# Returns true only if an action of this name was newly pressed this frame.
return Input.is_action_just_pressed(name)
func _input(event:InputEvent) -> void:
if _is_action_just_pressed(event, "jump"):
print("yay")
Both of those steps are needed because Input.is_action_just_pressed doesn’t check what kind of event was used to call it, only whether or not the action of that name was down that frame. _input() is called once by Godot for every input event that frame, so it needs to filter based just on that one event.
First, it’s a lot easier if you share the code as text. Use the code formatting, so it’s easier to read it on any screen, and to be able to copy/paste from it to edit it a bit. It helps a lot.
is_action_just_pressed() is a static method on the Input class itself. You can read about it here:
The error message is saying that rather than on Input, it was called on an instance of InputEventJoypadMotion, which doesn’t derive from Input. It could be for a lot of reasons, and none of them are clearly visible in the screenshot.
Maybe you forgot the _ in _is_action_just_presssed() in one place you called it?
I’d like you to read a bit about coding in GDScript and familiarize yourself a bit more with error messages, indenting issues, and such.
This has become a more basic/beginner’s problem than it was at first, which is fine! But it’s something that needs to be solved with reading the manual and looking for examples of code. Searching the net for the error message is one way to get there, as well.
If you get the function I suggested working but it doesn’t solve the issue, or you need more help understanding the reason why it works, then I’d be happy to help.
Also, if you can’t get it working after trying for a bit, I’ll take another look.
Looks like func dash() was returning when _is_dashing was active. I remember adding that in desperation a few days ago, but looks like that did the trick. Going to give it a timer now for dash length. Right now it’s working!
I’m glad you got it working! I’m sorry to have left you hanging a bit there at the end, but it seemed from multiple edits fixing Godot errors from tabs, that you needed to slow down and observe…