#how to make an enemy and a health system

1 messages · Page 1 of 1 (latest)

graceful magnet
#

Soo I'm working on my first project with zero experience and I didn't know how to make an enemy that can shoot the player and decrease their health gdthinking

faint frigate
#

u should watch few vids first XD

#

but In a nutshell u have to create a Character body 2D node

#

for the enemy itself

#

and a Area 2D to detect the player and shoot him

graceful magnet
#

Is it work on 3D node?

#

I made the navigation system and player movement and shooting etc

faint frigate
#

3D game?

graceful magnet
#

Yes

faint frigate
#

then character body 3D for the enemy

#

and Area 3D for player detection and shoot

graceful magnet
#

Oh that's it?? Thx

faint frigate
#

umm that are the nodes for now , also a lot of code to make it work XD

graceful magnet
#

It's ok thx anyways

acoustic imp
# graceful magnet Soo I'm working on my first project with zero experience and I didn't know how t...

Enemy should have an Area3D node and a CharacterBody3D (if it moves)
Use a signal to detect when the Player enters the enemy's Area3D radius
Connect the signal to a function/boolean to set it to attacking mode.
This can be a boolean such as var hostile : bool or func attack_player() -> void:
You could optionally make it so that the player is faster than the enemy and can actually exit the enemies range, if so... Put it in a while loop.
Now, you want to obviously have a cooldown for your shooting, so basically just store a variable called var shooting_cooldown : float,
Then make a timer node and set that timer to wait for timeout like so:

var timer := $Timer
timer.start(shooting_cooldown)
await timer.timeout

You could put this in a loop (for or while loop, whichever one you want)
Now to make the player actually DAMAGED, you need to detect if a bullet hit the player using something called groups.
Put all the bullets into a group called "bullets" when the shooting happens, and so now every time the player gets hit by something...
Check if the thing that hit the player is part of the "bullet" group. If not, then don't decrease their health.

Useful articles:
https://docs.godotengine.org/en/stable/tutorials/scripting/groups.html
https://docs.godotengine.org/en/stable/classes/class_area3d.html
https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html

Happy gamedev :)

graceful magnet
#

THX BROTHER