Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Trauma12 |
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 _physics_process(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)
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.
LeslieS | 2022-12-30 05:00