This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So...
I have a KB2D root node Scene called "Character.tscn", with a Script also called "Character.gd"

Then I have an inherited Scene (from Character.tscn) called "Player.tscn", with a Script that inherits from "Character.gd", called "Player.gd"

CHARACTER:

extends KinematicBody2D

const VELOCIDAD = 10
const VELOCIDAD_MAXIMA = 200
const FRICCION = 0.1

PLAYER:

extends "res://Personaje.gd"

func _process(delta):
pass

So far so good,BUT...
When I try to use for example moveandslide in Player.gd, GDScript doesn´t recognize it, as if it weren´t part of the built in methods. oddly enough it CAN print the variables assigned in the original script, so it seem to be inheriting just fine.

My question is: Do I need to do something else in order to get the kinematic functions, even if both scenes are KB2D?

I´ve seen some tutorials, but they don´t do anything else, besides setting the extend on line 1.
Seems something to simple to fail, yet it does. I´m using GODOT 3.1.1 by the way.

in Engine by (20 points)

I'm struggling with the same problem, i can't moveandslide from an inherited scene; can you explain how did you arranged your node tree?, what tutorial did you see that implemented this way of handling movement? any help would be great, thanks.

2 Answers

0 votes
Best answer

FIXED
just update to V 3.1.2 !!

by (20 points)
selected by
0 votes

I'm assuming "res://Personaje.gd" has the Character class.

Weird, PLAYER should have moveandslide. Could you run the code with PLAYER calling moveandslide and post the errors?

Also, I'd like to suggest using class_name to tidy up a bit.

newscript1.gd

extends KinematicBody2D
class_name NewScript1

newscript2.gd

extends NewScript1
class_name NewScript2
by (190 points)

Hey thanks for the advice and the swift response!

extends "res://Scripts/Personaje.gd"

var movimiento = Vector2()


func _process(delta):
    actualizar_velocidad(delta)
    move_and_slide(movimiento)


func actualizar_velocidad(delta):

    if Input.is_action_pressed("Arriba") and not Input.is_action_pressed("Abajo"):
        movimiento.y = clamp((movimiento.y -VELOCIDAD) , -VELOCIDAD_MAXIMA ,0)

    elif Input.is_action_pressed("Abajo") and not Input.is_action_pressed("Arriba"):
        movimiento.y = clamp((movimiento.y +VELOCIDAD) , 0 , VELOCIDAD_MAXIMA)
    else :
        movimiento.y = lerp(movimiento.y, 0, FRICCION)

    if Input.is_action_pressed("Izquierda") and not Input.is_action_pressed("Derecha"):
        movimiento.x = clamp((movimiento.x -VELOCIDAD) , -VELOCIDAD_MAXIMA ,0)

    elif Input.is_action_pressed("Derecha") and not Input.is_action_pressed("Izquierda"):
        movimiento.x = clamp((movimiento.x +VELOCIDAD) , 0 , VELOCIDAD_MAXIMA)
    else :
        movimiento.x = lerp(movimiento.x, 0, FRICCION)

Now i have actually tried it and it seem to work just fine, BUT the auto-complete keeps on suggesting methods for something else instead of KB2D:

master
mastersync
match
max(
min(
MARGINBOTTOM
movileVRinterface
ResourceFormatLoaderNativeScript
ResourceFormatLoaderVideoStreamGDNative

no move andslide sugestion for example, even if it can run.
Why is this happening? is there anything I can do to fix it?

Those are Godot's global stuff. They'll be suggested in any gdscript.

https://docs.godotengine.org/en/3.1/classes/[email protected]

Can't think of why your editor refuses to show moveandslide. I'm using Godot 3.1.2.

You´re right, I suspected that much. I´ll see if updating it fixes anything.

It´s probably my rig, It has another bug in the project management screen were the UI redraws itself one input delayed... kinda hard to explain, but I read somewhere that´s a common bug on some W10 versions.
Damn Windows.

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.