0 votes

Hi! So, I just started using Godot, and my idea for a game was a platformer where you play as a little water blob who can become either gas or ice. The problem is, I can't figure out how to make a code to make my character change. Anyone can help?

Godot version 3.3.2
in Engine by (12 points)

1 Answer

0 votes

hi,welcome to,godot,show me your script and your screen

by (28 points)

Alright, this is my code:

extends KinematicBody2D

enum {
    WATER,
    GAS,
    ICE
}

var velocity = Vector2(0,0)
const speed = 300
const gravity = 30
const jump = -700
var state = WATER

func state(state):
    match state:
        WATER:
            _physics_process(_delta)
        GAS:
            pass
        ICE:
            pass

func _physics_process(_delta):
    if Input.is_action_pressed("right"):
        velocity.x = speed
        $Sprite.play("Walk")
        $Sprite.flip_h = false
    elif Input.is_action_pressed("left"):
        velocity.x = -speed
        $Sprite.play("Walk")
        $Sprite.flip_h = true
    else:
        $Sprite.play("Idle")

    velocity.y = velocity.y + gravity

    if Input.is_action_just_pressed("Jump") and is_on_floor():
        velocity.y = jump
        $Sprite.play("Jump") 

    if not is_on_floor() and velocity.y < -200:
        $Sprite.play("Fly")

    if not is_on_floor() and velocity.y >= -200 and velocity.y <= 0:
        $Sprite.play("Fall")

    if not is_on_floor() and velocity.y > 0:
        $Sprite.play("Fall1")

    if not is_on_floor() and velocity.y > 100:
        $Sprite.play("Fall2")

    velocity = move_and_slide(velocity,Vector2.UP)

    velocity.x = lerp(velocity.x,0,0.2)

I tried using a state but it said tere was an error, the delta wasn't declared on the scope or something

maybe... use a animated sprite and not a normal sprite :)

Oh the name is sprite but it is an animated one. Forgot to change it

oh,what is the error ? show me your screen (your game)

if you whant to show an image or a video go to this website : https://wetransfer.com/

With that exact code I sent you the error is: "The identifier "_delta" isn't declared in the current scope."

the error color is red or yellow ?

It is the color red

in which line is the error?

the line 18, where it calls the physics process

ok last question,pizza or burger ?

Is it about real food or a code thingie?

If it is food i'd go with pizza I think

it's food lol,there is no pizza code or burger code

try this :

extends KinematicBody2D

enum {
WATER,
GAS,
ICE
}

var velocity = Vector2(0,0)
const speed = 300
const gravity = 30
const jump = -700
var state = WATER

func physicsprocess(delta):
if Input.isactionpressed("right"):
velocity.x = speed
$Sprite.play("Walk")
$Sprite.fliph = false
elif Input.is
actionpressed("left"):
velocity.x = -speed
$Sprite.play("Walk")
$Sprite.flip
h = true
else:
$Sprite.play("Idle")

velocity.y = velocity.y + gravity

if Input.is_action_just_pressed("Jump") and is_on_floor():
    velocity.y = jump
    $Sprite.play("Jump")

if not is_on_floor() and velocity.y < -200:
    $Sprite.play("Fly")

if not is_on_floor() and velocity.y >= -200 and velocity.y <= 0:
    $Sprite.play("Fall")

if not is_on_floor() and velocity.y > 0:
    $Sprite.play("Fall1")

if not is_on_floor() and velocity.y > 100:
    $Sprite.play("Fall2")

velocity = move_and_slide(velocity,Vector2.UP)

velocity.x = lerp(velocity.x,0,0.2)

func state(state):
match state:
WATER:
physicsprocess(delta)
GAS:
pass
ICE:
pass

It said the same thing: "The identifier "delta" isn't declared in the current scope."

Fixed it! Dumbass me wrote the state(delta) wrong

that what i changed in the script,so that work now ?

It does, thank you!

Click here
and here
lol im 12 yo

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 webmaster@godotengine.org with your username.