#How to differentiate between different projectiles attacks?
68 messages · Page 1 of 1 (latest)
Is the only difference the amount of damage between the attacks?
Or are there more differences?
mostly the amount of damage (and for one attack, I am planning for a stun, though I probably wont do that now) but for now, the amount of damage. I just wonder how do people normally differentinate between projectils.
So most would make a default projectile script
Where you can store all basic information about a projectile
That you create a script for each different attack
And give the seperated values.
Haha how many do you have?
I just have two (and I guess a lighting attack I have, which is more of a special attack) but mostly focusing on the two projectiles I want to finish up, so two I would say
Can you share both codes?
alright
magicorb projectile
extends CharacterBody2D
var speed = 100
@onready var SFX = $SFX
func _ready() -> void:
SFX.play()
func _process(delta):
velocity.x = speed
move_and_slide()
func _on_kill_timer_timeout():
queue_free()
the standard projectiles
extends CharacterBody2D
var speed = 0
@onready var sprite = $Sprite2D
@onready var magicContact = $Area2D
var lenght = 50
var point = Vector2()
@onready var trail = $CPUParticles2D
#@onready var particle_reverse = load("res://Startup/Player/Amanda/melee-beam_reverse.png")
#@onready var particle = load("res://Startup/Player/Amanda/melee-beam.png")
func _physics_process(delta: float) -> void:
velocity.x = speed
#get direction
move_and_slide()
for enemiesInBodies in magicContact.get_overlapping_bodies():
if enemiesInBodies.is_in_group("enemy"):
queue_free()
for enemiesInArea in magicContact.get_overlapping_areas():
if enemiesInArea.is_in_group("enemy"):
queue_free()
https://youtu.be/sZDJJeDNe_M?si=bOBjYA_HyW2VwpSq
Found this tutorial awhile ago that should give you an idea about an approach to different attacks/attack modifiers if you wanna give it a shot
In this video we'll look at an application of the Strategy Pattern to game dev in Godot 4.
The Strategy Pattern is a programming pattern useful for switching how an algorithm works at runtime. We use it a little differently here to apply a variable set of upgrades to a projectile fired by the player. A very closely related term is "polymorphism...
Or that, you could indeed watch a video haha
You need to put the extends on the next line when you do that
extends CharacterBody2D
var speed = 100
@onready var SFX = $SFX
func _ready() -> void:
SFX.play()
func _process(delta):
velocity.x = speed
move_and_slide()
func _on_kill_timer_timeout():
queue_free()
But I gues not with this code
Nevermind
Do you want my help or are you gonna watch the video first? 🙂 @night ingot
I am more than happy to help
I will have your help first, sure!
So this is 1 projectile?
And this the other?
yes
they are both seperate projectiles for seperate attacks
standard being for the most basic attack
The most basic attack doesn’t have visuals?
the magicorb also have visuals, yeah
it shoot a bunch of orbs in front of the player
Alright
Okay let’s put it this way
When you are gonna use something a lot of times
It’s easier to make a default
For example both are CharacterBody2D’s
If that’s gonna be a standard, you could make a default script,
Extends CharacterBody2D
class_name BasicProjectile
Than in the other 2 files you can extend BasicProjectile instead of CharacterBody2D
oooh
Now you can think of things every projectile will have
Speed, sound, etc
Put all of that in the default script
By extending every new projectile to the default one
Everything in default
Will be implemented
🙂
No problem for just a small example what you can do this way is this
In the default script you have a function on_hit
And the variable var damage : Int
In another script you extend Default and set the damage = 10
Now in your enemy script you can handle the on_hit, by calling the default on_hit function, which automatically calls the damage variable from this attack.
This way the only thing you have to change for every spell is the damage
All functions stay usable and don’t need copy pasting!
oh wow. yeah, that would be very useful!
you really helped me out
I am very thankful
No problem man, happy to help, let me know if there is anything else I can do for you, but this is the commonly used approach when using stuff you are gonna use a lot of differentiates of