Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ShaneGrey413 | |
Old Version | Published before Godot 3 was released. |
**I am getting this error:**Invalid call. Nonexistent function ‘move_and_slide’ in base ‘KinematicBody2D (KinematicBody2D.gd)’.
I don’t know why… I am following a tutorial and it is LITERALLY the exact same and he didn’t get an error. Can you tell me what’s wrong with my script and how to fix it? Here’s the link to the video https://www.youtube.com/watch?v=Viaslrr1Md4
Here’s my script:
extends KinematicBody2D
#Laws of Physics
const GRAVITY = Vector2(0, 500)
#Movement Contants
const FLOOR_NORMAL = Vector2(0, -1)
const SLOPE_FRICTION = 28
const MOVEMENT_SPEED = 400
const ACCELERATION = 1
const JUMP_FORCE = 200
#Player Variables
var velocity = Vector2()
var can_jump = false
#Start
func _ready():
set_fixed_process(true)
#Processing
func _fixed_process(delta):
#Add Gravity
velocity += GRAVITY * delta
#old:
#move(velocity)
#new:
#Move and Slide
velocity = move_and_slide(velocity, FLOOR_NORMAL, SLOPE_FRICTION)
# Movement
var movement = 0
if(Input.is_action_pressed("ui_left")):
movement -= 1
if(Input.is_action_pressed("ui_left")):
movement += 1
movement *= MOVEMENT_SPEED
# Change horizontal veloctiy
velocity.x = lerp(velocity.x, movement, ACCELERATION)
#Input: Jump
if(can_jump && Input.is_action_pressed("ui_up")):
velocity.y -= JUMP_FORCE
can_jump = false