0 votes

Hello, i encounter this problem while copy and paste a code that i found in here,
please take note i just started godot not even within 24 hour since this question is posted, what i am trying to dulpicate is a feature that will make the obeject (player) move to any location that is touch in the screen,

again here are the error:
Script inherits from native type 'KinematicBody2D', so it can't be instanced in object of type 'Node2D'.

and here are the script :

extends KinematicBody2D

const GRAVITY = 20

const MAXSPEED = 200
const JUMP
HEIGHT = -500
const UP = Vector2(0,-1)

var motion = Vector2()

enum STATES {

onready var state = STATES.Idle

func input(event):
if event is InputEventMouseButton and event.button
index == BUTTONLEFT:
if event.pressed:
var local
event = makeinputlocal(event)

        if local_event.position.x > 20: #and local_event.position.y > -50:
            state = STATES.MoveRight
        elif local_event.position.x < -20: #and local_event.position.y > -50:
            state = STATES.MoveLeft
        elif round(local_event.position.y) in range(-400, -20):
            state = STATES.Jump
        state = STATES.Idle

func physicsprocess(delta):
motion.y += GRAVITY
var friction = false
match state:
motion.x = min(motion.x+ACCELERATION, MAXSPEED)
h = false
motion.x = max(motion.x-ACCELERATION, -MAXSPEED)
h = true
friction = true
if isonfloor():
motion.y = JUMP_HEIGHT
if friction == true:
motion.x = lerp(motion.x, 0, 0.2)
if motion.y < 0:
if friction == true:
motion.x = lerp(motion.x, 0, 0.1)

motion = move_and_slide(motion, UP)

Thank you for helping

Godot version 3.3.2 stable
in Engine by (17 points)

1 Answer

0 votes

You seem to have attached this script to a node that isn't a KinematicBody2D.

The script begins with extends KinematicBody2D so it can't be attached to a Node2D.

by (20,479 points)

Hye thanks for the fast reply,

i have now move the script and attach it with KinematicBody2D now a new error came up

error(21,1): Indented block expected after declaration of "input"

here is the full script ( not sure if the forum set the script correctly so i paste it to another site)

Script Link

That copy-and-paste has completely destroyed all the necessary code formatting. GDScript requires indentation to indicate code blocks.

func _ready():
    print("hello world")


func _ready():
print("hello world")

oh my.. well i will make a proper question from beginning then, how can i delete this question

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.