Godot Version
Godot 4
Question
I want a set spawn point on teleport zones theres whole code and maps
extends CharacterBody2D
var enemy_inattack_range = false
var enemy_attack_cooldown = true
var health = 100
var player_alive = true
var attack_ip = false
const speed = 80
var current_dir = “none”
const FRICTION = 30
func _physics_process(delta):
enemy_attack()
player_movement(delta)
attack()
current_cam()
if health <= 0:
player_alive = false
health = 0
print(“player dead”)
$AnimatedSprite2D.play(“death”)
self.queue_free()
func player_movement(delta):
if Input.is_action_pressed(“ui_right”):
velocity.x = speed
play_anim(1)
velocity.y = 0
current_dir = “right”
elif Input.is_action_pressed(“ui_left”):
velocity.x = -speed
play_anim(1)
velocity.y = 0
current_dir = “left”
elif Input.is_action_pressed(“ui_down”):
velocity.x = 0
play_anim(1)
velocity.y = speed
current_dir =“down”
elif Input.is_action_pressed(“ui_up”):
velocity.x = 0
play_anim(1)
velocity.y = -speed
current_dir = “up”
else:
play_anim(0)
velocity.x = 0
velocity.y = 0
move_and_slide();
func play_anim(movement):
var dir = current_dir
var anim = $AnimatedSprite2D
if dir == “right”:
anim.flip_h = false
if movement == 1:
anim.play(“left_walk”)
elif movement == 0:
if attack_ip == false:
anim.play(“left_idle”)
if dir == “left”:
anim.flip_h = true
if movement == 1:
anim.play(“left_walk”)
elif movement == 0:
if attack_ip == false:
anim.play(“left_idle”)
if dir == “down”:
anim.flip_h = false
if movement == 1:
anim.play(“front_walk”)
elif movement == 0:
if attack_ip == false:
anim.play(“front_idle”)
if dir == “up”:
anim.flip_h = false
if movement == 1:
anim.play(“back_walk”)
elif movement == 0:
if attack_ip == false:
anim.play(“back_idle”)
func player():
pass
func _on_hitbox_player_body_entered(body):
if body.has_method(“enemy”):
enemy_inattack_range = true
func _on_hitbox_player_body_exited(body):
if body.has_method(“enemy”):
enemy_inattack_range = false
func enemy_attack():
if enemy_inattack_range and enemy_attack_cooldown and global.mob_alive:
health = health - 10
enemy_attack_cooldown = false
$cooldown_timer.start()
print(health)
func _on_cooldown_timer_timeout():
enemy_attack_cooldown = true
func attack():
var dir = current_dir
if Input.is_action_pressed(“e”):
global.current_player_attack = true
attack_ip = true
if dir == “right”:
$AnimatedSprite2D.flip_h = false
$AnimatedSprite2D.play(“left_attack”)
$deal_attack_timer.start()
if dir == “left”:
$AnimatedSprite2D.flip_h = true
$AnimatedSprite2D.play(“left_attack”)
$deal_attack_timer.start()
if dir == “down”:
$AnimatedSprite2D.flip_h = false
$AnimatedSprite2D.play(“front_attack”)
$deal_attack_timer.start()
if dir == “up”:
$AnimatedSprite2D.flip_h = false
$AnimatedSprite2D.play(“back_attack”)
$deal_attack_timer.start()
func _on_deal_attack_timer_timeout():
$deal_attack_timer.stop()
global.current_player_attack = false
attack_ip = false
func released():
if Input.is_action_just_pressed(“e”):
if current_dir == “right”:
$AnimatedSprite2D.flip_h = false
$AnimatedSprite2D.play(“left_attack”)
$deal_attack_timer.start()
if current_dir == “left”:
$AnimatedSprite2D.flip_h = true
$AnimatedSprite2D.play(“left_attack”)
$deal_attack_timer.start()
if current_dir == “down”:
$AnimatedSprite2D.flip_h = false
$AnimatedSprite2D.play(“front_attack”)
$deal_attack_timer.start()
if current_dir == “up”:
$AnimatedSprite2D.flip_h = false
$AnimatedSprite2D.play(“back_attack”)
$deal_attack_timer.start()
func current_cam():
if global.current_scene == “dunya”:
$dunya_cam.enabled = true
$zone_2_cam.enabled = false
elif global.current_scene == “zone_2”:
$dunya_cam.enabled = false
$zone_2_cam.enabled = true
Global Node
extends Node
var current_player_attack = false
var mob_alive = true
var current_scene = “dunya”
var transition_scene = false
var zone_2_to_dunya_posx = 256
var zone_2_to_dunya_posy = -144
var dunya_to_zone_2_posx = 1
var dunya_to_zone_2_posy = 1
var loading_on_dunya = true
var loading_on_zone_2 = false
func finish_changescenes(zone):
if transition_scene == true:
transition_scene = false
if zone == “zone_2”:
current_scene = “zone_2”
elif zone == “dunya”:
current_scene = “dunya”
I can send zone codes etc I dont know which one u need
there is maps
I want to spawn in front of blue zones
