0 votes

I am trying to make a sprint system for my game but I am unsure how to make my character run only when I am holding down a key because right now the character stays sprinting forever. This is the code I am using:
func _input(event): if(event.is_action_pressed("sprint")): walk_speed = 6.0 print("Sprint Pressed!")

Thanks!

Godot version 3.3.2
in Engine by (13 points)

2 Answers

0 votes

This is because the _input function is called once per event. So you press the button and set the character sprinting.

So you need to add an action for stopping the sprinting i.e. a release of the key.

by (191 points)
+1 vote

my movement code looks always abit like this:

func physiksprocess(delta):

if Input.isactionpressed("moveforward"):
move
andcollide(transform.basis.x * movespeed * delta)
if Input.is
actionpressed("movebackward"):
moveandcollide(-transform.basis.x * movespeed * delta)

i hope this helps

by (213 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.