#Help setting up movement component :S

1 messages · Page 1 of 1 (latest)

fallen oyster
#

So I have this basic prototype where I have an enemy and a bullet that gets constantly spawned.

This is my first Godot project where I actually try and I'm currently learning classes and components:

My player now takes a HitboxComponent, an AttackComponent and a HealthComponent and the logic is handled by the main Player script.

Now, I'm trying to set up a MovementComponent to assign to the bullet and the player. And I have a lot of questions:

First, since the bullet is, well, a bullet; It is an Area2D, while the player is a CharacterBody2D.
This implies that the player has a velocity which doesn't need delta while the bullet does not. So if I try to set up functions for movement inside the MovementComponent, the functions would take delta for the bullet but not for the character2D.

Should I change the bullet to be CharacterBody2D? That would make it collide with the player, right? Would that also affect performance faster as I spawn more bullets?

If I keep them as Area2D, should I make two functions for Area2D's and then for the characters? Should I make 2 different movement components?

Is there any GDScript example for A MovementComponent?

hazy current
#

I think you shouldn't be overly concerned with generalising your code that much.

Think about the inputs and outputs of a player movement component. I presume it takes keyboard/mouse/gamepad actions and axes, and it controls a CharacterBody. Then consider whether you'll need to replicate the same exact behaviour on other kinds of characters or objects.

Then consider the inputs and outputs of movement for a bullet. Presumably it's given a direction and speed, and directly moves a regular Node2D. That's quite different from the player movement, right? That's why I'd never try to mix the two.

fallen oyster
#

enemies, bullets, the player itself and everything that moves all have a direction and a speed, then I'd modify them giving the effects I want (functions for each one).

The input or how the movement is triggered would be handled by the main script but the code that determine how it moves can be all inside a MovementComponent.

#

Then I could do stuff like making the player have linear movement, then ease in or ease out or bouncy etc or no movement at all, same for bullets/enemies as I see fit

#

That's why I think it'd be useful and I think it can/should be generalized