+1 vote

Hello, I'm making a game, in which an enemy is a crocodile that is safe to walk on when its mouth is closed, but when its mouth is open, it will hurt the player. How exactly would I code this? Thank you.

in Engine by (19 points)

1 Answer

0 votes

To give an exact answer, we would need to know how your player is detecting the damage and the overall setup of your nodes. Otherwise it won't adapt very well.

Having said that, one idea is to set up a bool variable canTakeDamage (or similar). And link the animation of the crocodile to that variable. You may need to use custom signals (again we don't know your setup).

The code would look something like this:

var canTakeDamage : bool = false

func healthDown():
   if canTakeDamage:
      //your code to react to damage

Hope this helps giving you some ideas to apply to your game.

by (71 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.