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:
Spike:
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():
Close
spike()

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

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

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

func onLazerOpenspike():
Open_spike()

func onLazer2Openspike():
Open_spike()

func onLazer3Openspike():
Open_spike()

func onLazer4Openspike():
Open_spike()

func onLazer8Openspike():
Open_spike()

Lazer:
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):
Lazer_Checking()

func LazerChecking():
if Triped and !Has
beenTriped:
$Sprite.texture = Yellow
Lazer
Triped = false
$Timer.start(0.05)
HasbeenTriped = true
if Triped and HasbeenTriped:
$Sprite.texture = RedLazer
emit
signal("Openspike")
Lazer
detected = true
Reset = true
$Timer.start(5)
else:
$Sprite.texture = Green_Lazer

func onLazerbodyentered(body):
if "Player" in body.name:
#emitsignal("Openspike")
print("start")
$Timer.start(0.05)

func onTimertimeout():
if !Reset:
Triped = true
print("end")
if Reset:
print("reseted")
Reset = false
Has
been_Triped = false
Triped = false

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

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,484 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 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.