The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I have a problem in the code. I'm using GDScrip and I'm new to this. I am copying the code from a tutorial and I do not see the error.Is it possible that the tutorial is out of date?

extends KinematicBody2D

const moveSpeed = 25
const maxSpeed= 50

const jumpHeight = -300
const up = Vector2 (0,1)

const gravity = 15

onready var sprite = $Sprite
onready var animationPlayer = $AnimationPlayer

var motion = Vector2()

func physicsprocess(delta):

motion.y += gravity

var friction = false

if Input.is_action_pressed ("ui_right"):
      sprite.flip_h = true
      animationPlayer.play("walk")
      motion.x = min(motion.x + moveSpeed, maxSpeed)

elif Input.is_action_pressed ("ui_left"):
      sprite.flip_h = false
      animationPlayer.play("walk")
      motion.x = max (motion.x - moveSpeed, maxSpeed)

else:
    animationPlayer.Play("Idle")
    friction = true

if is_on_floor():
    if Input. is_action_pressed("ui_accept"):
        motion.y = jumpHeight
    if friction == true:
        motion.x = lerp (motion.x, 0, 0.5)
else:
    if friction == true:
        motion.x = lerp (motion.x, 0, 0.01)

motion = move_and_slide(motion, up)
in Engine by (12 points)

Can you describe the error?
Note that because of the messed up formatting I see more than 1 error but I am guessing that is just printing wrong.
The best way to post code in this format is to copy/paste from the editor into the text box then select all the code and press the {} on the toolbar above the text box.
Please edit your post to fix that.

1 Answer

0 votes
else:
    animationPlayer.Play("Idle")
    friction = true

In this line Play should be written with a lowercase p

 else:
    animationPlayer.play("Idle")
    friction = true. 

I don't know if that is your problem but it is something I spotted. I am also not an expert so there is a possibility that I missed something else.

EDIT:

 func physicsprocess(delta):

Should be written as

func _physics_process(delta):
by (35 points)
edited by
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 [email protected] with your username.