0 votes

Hello I have been working on this game and I made this lazer that goes one and one with a spike which when the lazer gets touched for too long the spikes will activate(note that my player doesn't have any hp so there is no tanking dmg) but when my lazer activates the spike wont close so you will come to an end and will have to go to menu and re play I have also thought of the possiblity of making it when you die just reset that scene but after remembering the finale level reseting the scene will reset your progress in the level so I am trying to avoid that at all costs. I have already made a closing function and it works when I activate it inside of my ready function but if I try to call it when the player dies it doesn't work(though it wouldn't be good as it will only close that certain spike). Just to clarify my problem is to reset my spike and I also will need a way to reset the Lazer
Here is my code if you need:
extends Area2D

const OpenSpikeSprite = preload("res://Assests/Tile Set/Open Spike.png")
const SpikeHolderSprite = preload("res://Assests/Tile Set/Spike Holder.png.png")

func ready():

func Openspike():
$Sprite.texture = Open
$CollisionPolygon2D.disabled = false

func Closespike():
$Sprite.texture = Spike
$CollisionPolygon2D.disabled = true

func onSpikebodyentered(body):
if "Player" in body.name:

func onLazerOpenspike():

func onLazer2Openspike():

func onLazer3Openspike():

func onLazer4Openspike():

func onLazer8Openspike():

extends Area2D

const GreenLazer = preload("res://Assests/Tile Set/Green Lazer.png.png")
const Yellow
Lazer = preload("res://Assests/Tile Set/Yellow Lazer.png.png")
const Red_Lazer = preload("res://Assests/Tile Set/Red Lazer.png.png")

var Triped = false
var HasbeenTriped = false
var Lazer_detected = false
var Reset = false

signal Open_spike

func physicsprocess(delta):

func LazerChecking():
if Triped and !Has
$Sprite.texture = Yellow
Triped = false
HasbeenTriped = true
if Triped and HasbeenTriped:
$Sprite.texture = RedLazer
detected = true
Reset = true
$Sprite.texture = Green_Lazer

func onLazerbodyentered(body):
if "Player" in body.name:

func onTimertimeout():
if !Reset:
Triped = true
if Reset:
Reset = false
been_Triped = false
Triped = false

func onLazerbodyexited(body):
if !Lazerdetected:
$Sprite.texture = Green

Godot version v3.2.2
in Engine by (20 points)

1 Answer

0 votes

If all your spikes share the same parent node, in that mother of all spikes, you could do :
for spike in get_children():
. spike.close_spike()

Otherwise, if only the player can open them, you could :

  • Put a reset signal in the player.
  • When a spike opens, it has access to the coliding player. You use this to connect its close_spike() to the players reset signal (CONNECT_ONCE).
  • When you emit the reset signal, all the spikes that where open close themselves.
by (2,634 points)
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.