bulletStoper bug for Godot course

So, if you fire two shots, bot in the same “line”, one further than the other, the bullet that will destroy the bulletStoper will be the first bullet to enter it, not the one that spawn it. bulletStoper detects a collision with an ally bullet, but if its not the one that spawned it it shouldnt trigger, but it does.

h hi Pau,

Sorry its taken me a little while to get round to replying, had to try and figure out a way to get round it :slight_smile:

(ive also added the question to the Godot CSharp Tag so it can be found more easily)

the ability to fire with only one bullet on screen is covered in the " limiting Ammo " section and that gets around the issue with only having one player bullet and one bullet stopper on screen. did that not work for you?

but, just as a little test and depending how comfortable with c# and Godot you are, what I have done was that when a bullet is fired, it takes a reference to that bullet and sets that within its correspondingly created stopper. so when a bullet enters the stopper, it checks to see if the entered bullet reference is the same as that which was matched when it fired.

what i done as a test was:
in the CannonBarel.cs script to grab a reference to the bullet fired, at the top of the ShootAtMouse() method i added the line

bullet _bulletRef = bulletBrain.spawnBullet(GlobalPosition, GetGlobalMousePosition(), "player");

then just under this line in the same script

var bulletStopper = (Area2D)scenes._sceneBulletStopper.Instance();

i put the following two lines (didnt have time to suss out a better way of calling a method on it

bulletStopper bsRef = bulletStopper as bulletStopper;
bsRef._set_bullet_reference(_bulletRef);

so i had to add another method and variable to store the bullet reference to the bulletStopper.cs script
so within bulletStopper.cs the variable declared at top

bullet _bulletRef;

then a public method in there to set it, when its instantiated

public void _set_bullet_reference(bullet _ref)
	{
		_bulletRef = _ref;
	}

then within the _on_bulletStopper_area_entered method, i just added a line shown by the comment
ive shown a chunk of it, so you can see where ive placed it

public void _on_bulletStopper_area_entered(Area2D bullet)
{
var bulletType = (AnimatedSprite)bullet.GetNodeOrNull(“AnimatedSprite”);
if((bulletType != null) && (bulletType.Animation == “player”) && (bullet is bullet))
{
if (bullet == _bulletRef) // *****added this line to check its the corresponding bullet
bulletBrain.CallDeferred(“spawnExplosion”,GlobalPosition,“player”);
bullet.QueueFree();
QueueFree(); //Destroys bulletStopperdded another IF statement to check its the right reference.

so that was the way i thought about doing it and its very much outside the scope of the course, but it does rear other gameplay issues on the back of it. for me, I just returned it to the way Tim had id within the Limiting Ammo lecture as for me it felt better gameplay and more tactical only having one bullet on screen at a time.

hope that wee bit of info helps.
DaZ

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms