Help with making my character changing into another

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Adrian Monky

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?

:bust_in_silhouette: Reply From: Lgdn

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

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

Adrian Monky | 2021-08-01 12:36

maybe… use a animated sprite and not a normal sprite :slight_smile:

Lgdn | 2021-08-01 12:58

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

Adrian Monky | 2021-08-01 13:00

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/

Lgdn | 2021-08-01 13:03

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

Adrian Monky | 2021-08-01 13:10

the error color is red or yellow ?

Lgdn | 2021-08-01 13:11

It is the color red

Adrian Monky | 2021-08-01 13:14

in which line is the error?

Lgdn | 2021-08-01 13:16

the line 18, where it calls the physics process

Adrian Monky | 2021-08-01 13:17

ok last question,pizza or burger ?

Lgdn | 2021-08-01 13:20

Is it about real food or a code thingie?

Adrian Monky | 2021-08-01 13:22

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

Adrian Monky | 2021-08-01 13:22

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

Lgdn | 2021-08-01 13:24

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 _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)

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

Lgdn | 2021-08-01 13:29

It said the same thing: “The identifier “delta” isn’t declared in the current scope.”

Adrian Monky | 2021-08-01 13:33

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

Adrian Monky | 2021-08-01 14:20

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

Lgdn | 2021-08-01 16:50

It does, thank you!

Adrian Monky | 2021-08-01 19:35

Click here
and here
lol im 12 yo

Lgdn | 2021-08-09 12:24