Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement explosion damage for missile based weapon #12

Closed
danilko opened this issue May 23, 2021 · 3 comments
Closed

Implement explosion damage for missile based weapon #12

danilko opened this issue May 23, 2021 · 3 comments

Comments

@danilko
Copy link
Owner

danilko commented May 23, 2021

As a player, I want missile type weapon to have explosion effect to impact blast area

Similar effect as describe in
https://www.youtube.com/watch?v=xPk9cxHrPrU

@danilko
Copy link
Owner Author

danilko commented Oct 31, 2021

After experimentation, move way from initial raycast based explosion
https://www.youtube.com/watch?v=xPk9cxHrPrU

To a simpler area2D explosion

The reason is the performance can drop to 10 FPS under certain cases when there are 5 - 10 missile explosion happen once.

If reducing the raycast number to lower number, it seem the explosion effect is not that realistic (i.e 60 rays as oppose to 200 rays).

Utilize area2D seem to be much perform as the FPS remain around 60 even with 5 - 10 missile explosions. The tradeoff is less accuracy but overall seem good enough in some degree.

Also utilize deferred method to dynamically adjust raycast parameters

During missle explosion, utilize deffered to avoid warning Recommend to use deffered (reference from here godotengine/godot#33766)

In Missile.cs


    public override void Explode()
    {
        base.Explode();

        CallDeferred("createExplosion");

        QueueFree();
    }

    private void createExplosion()
    {
        ExplosionBlast explosionBlast = (ExplosionBlast)((PackedScene)GD.Load("res://projectiles/ExplosionBlast.tscn")).Instance();
        GameWorld.AddChild(explosionBlast);
        explosionBlast.Initialize(Source, SourceTeam,  GameWorld, DamageRayRadius, Damage, GlobalPosition);
    }

Also in ExplosionBlast.cs

    public void Initialize(Node2D source, Team sourceTeam, GameWorld gameWorld, float raidus, float damage, Vector2 position)
    {
        CollisionShape2D detectRadius = (CollisionShape2D)GetNode("CollisionShape2D");

        // Use SetDeferred to change the pyhsic world when it is ready
        // reference from here https://github.com/godotengine/godot/issues/33766
        ((CircleShape2D)(detectRadius.Shape)).SetDeferred("radius", raidus);

        Source = source;
        SourceTeam = sourceTeam;
        Damage = damage;

        // Set the parent to gameworld
        if (!IsConnected(nameof(ExplosionBlastDamageSignal), gameWorld, "_onDamageCalculation"))
        {
            Connect(nameof(ExplosionBlastDamageSignal), gameWorld, "_onDamageCalculation");
        }

        GlobalPosition = position;

        AgentExplosionParticle agentExplosionParticle = (AgentExplosionParticle)GetNode("AgentExplosionParticle");
        agentExplosionParticle.SetTrigger(true);

        IsInitialize = true;
    }

@danilko
Copy link
Owner Author

danilko commented Oct 31, 2021

Also change overall projectile from raycast + area2D to pure Area2D again.

As it seem with godot 3.3.4, the Physics for Area2D are much more accurate alone.

This allows better performance for browser based export.

danilko pushed a commit that referenced this issue Nov 1, 2021
…y as Godot 3.3.4 seem able to handle it well with Area2D alone. Also move alway from explosion with raycast2ds into one Area2D. Both aim to improve performances and confirmed through web export that stays around 30 FPS (60 FPS local) even with 5 - 10 explosions at same time
@danilko
Copy link
Owner Author

danilko commented Dec 12, 2021

Close the issue with current implementation

@danilko danilko closed this as completed Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant