Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Charge Weapon Spawn Position

A topic by m0nkeybusiness created 37 days ago Views: 71 Replies: 6
Viewing posts 1 to 7

Hello OscarVezz,

When I use your pre-built charging system I run into the following problem.

I run the following code in the _process func of my weapon script. 


if charging and Input.is_action_pressed("mb_left"):
projectile_manager.request_execution(0,0,end_of_gun.global_position,get_global_mouse_position())
if Input.is_action_just_released("mb_left"):
charging = false


The weapon gets charged properly and discharges at the correct time BUT the projectile is not spawned where the last "request_execution" method call happened but at the position where I started charging the weapon. 

For charge-type CONTINUOUS  this means where I started pressing the left mouse button.

For DISCRETE this means where I started the charging intervall that triggered the discharge. Independently of how much it was charged already.

For MANDATORY this means were I pressed the mouse button.

Activating "position override" introduces new problems and I would prefer to spawn the bullet at a position of my choosing.

Is that a mistake on my side? If so it would be greatly appreciated if you could point me into the right direction. Or maybe it is a bug and you did not encounter it because the grand frog mage (!) in your example scenes is stationary?

Thank you in advance

After further testing I realized that the destination value has the same problem than the spawn point. It is not derived from the last method call but from the first. Taking this in consideration the overwrite position would most likely actually work but still limits the possibilites. Furthermore I would need a overwrite destination then as well. Making it work without "overwrite" would still be preferable to me.

Developer (3 edits)

Managing attacks is a bit complex but don’t worry, let’s break it down:

As you inferred, whenever you request an attack, the first position and destination parameters given are the ones that will be used throughout the rest of the attack.

This behavior is intentional by design so your attacks can whiff:

However you still have some quick tools to overwrite this:

When you overwrite position, you are telling the attack to ignore any given positions and to use its own physical Node position instead, and so you can dictate your final result just by modifying its position:

func _process(_delta: float) -> void:
...
	# -> Like this!
	projectile_manager.global_position = end_of_gun.global_position

	if charging and Input.is_action_pressed("mb_left"):
		projectile_manager.request_execution(0, 0, end_of_gun.global_position, get_global_mouse_position())
...

In case you need more control or you don’t want to use the overrides, you will have to modify the behavior of your attacks:

func _ready() -> void:
	# -> Here we set the methods themselves on the attack
	projectile_manager.get_attack(0).set_on_charge_exit(on_charge_exit).set_on_main_enter(on_main_enter)


func on_charge_exit(attack: Attack2D) -> void:
	# -> Here we are setting the final destination *only* when the charge is finished.
	# -> "pi" refers to *PackedInfo*, a helper class that stores all the information about how a projectile is initialized.
	attack.pi.destination = get_global_mouse_position()
	attack.charge_exit()


func on_main_enter(attack: Attack2D) -> void:
	# -> Here we are setting the projectile position, just before spawning.
	attack.pi.position = end_of_gun.global_position
	attack.main_enter()

All of this will be explained in the Documentation, again sorry it is not finished yet but I hope this clarification will help you in your project!

I’m here if you need more help. Regards.

Hello and again thank you for the detailed answer! Really appreciate it. 

I am sorry if I am looking in the wrong location but at the position where I can activate "Override Position" there is no "Override Destination" like in your example picture.

I am using 1.3. of the plugin. That is the current version correct?

TY again

Developer

Indeed, the 1.3 version is the most recent one. The “override destination” property is a small slip from the next 1.4 update.

In fact, if you have any feature suggestions feel free to tell me and they may be included in the next patch!

Thats great. I can tell you things that I thought of but I can not guarantee, that they are not possible already. So if they are possible a small tip how to achieve it would be awesome.


Bounces: Bouncing back from walls and objects. Godot 4.4. (I think?)  introduced more constistent TileSet Collisions so that should help there too.

Charge up before firing: I know a charge before every shot is possible. But is there the option for a single charge before firing automatically without charges in between shots? Think of an Minigun for instance. 


I am sure when I will implement more guns and work more with your plugin ideas will come and I will let you know! Thank you so much.

On that note, do you know when you will come around publishing 1.4.? Cheers