0 votes

Its hard to find how to sprint code and i dont know how to do it,not in 3d,but sprinting in 2d,help

Godot version Recent godot
in Engine by (16 points)
recategorized by

maybe increase your move speed, when you click sprinting button?
example :
if event.is_action_pressed("R_click"): move_speed = 200

Did that,but for some reason the animation didnt work

1 Answer

+1 vote

if you don't want to make that big of change to your current code base, assuming you have:

var velocity = Vector2.ZERO
var acceleration = 10

func _physics_process(delta):
 if Input.is_action_pressed("right"):
  velocity.x += acceleration 
 velocity = move_and_slide(velocity)

For your movement code, you could simply add:

var speed_bonus = 0

func _physics_process(delta):
 if Input.is_action_pressed("right"):
  velocity.x += acceleration + speed_bonus

 if Input.is_action_pressed("shift_run"):
  speed_bonus = 10
 else:
  speed_bonus = 0
 velocity = move_and_slide(velocity)
by (334 points)

Well it worked but,the animation didnt,whenever i tried to move the player,the animation just froze amd doesmt animate,it worked if i use it for anything else but it just doesnt work whenever i tried to use the sprint code

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 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.