public void BodyEntered(Node body) { //GD.Print("body.Name = " + body.Name); //Check if it hit a map element first if (body.IsInGroup("Map")) { MapUpdateEvent muei = new MapUpdateEvent(); //Add one more step of velocity to the colliders position so that we make sure the bullet is inside the tile before we //return the bullets position to the map for refferencing the tile that was hit velocity = new Vector2(Mathf.Cos(Rotation), Mathf.Sin(Rotation)) * speed / 2; muei.CollisionPos = Position; muei.FireEvent(); QueueFree(); } //If the collider was not a wall or in the same group as the object that fired it call the hit event else if (body != GetParent().GetParent()) { //Fire of the hit event HitEvent hei = new HitEvent(); hei.target = (Node2D)body; hei.attacker = (Node2D)GetParent().GetParent(); hei.damage = 100; hei.FireEvent(); QueueFree(); } }
public void RigidBody2DBodyEntered(Node body) { if (body.IsInGroup("RedBlob")) { HitEvent hei = new HitEvent(); hei.target = (Node2D)body; hei.attacker = (Node2D)GetParent(); hei.damage = 50; hei.FireEvent(); } if (body.IsInGroup("BlueBlob")) { if (((BlueBlobCollision)body).Infected()) { HitEvent hei = new HitEvent(); hei.target = (Node2D)GetParent(); hei.attacker = (Node2D)body; hei.damage = 100; hei.FireEvent(); } } PlayAudioEvent paei = new PlayAudioEvent(); paei.soundEffectType = SoundEffectType.HIT; paei.AudioTarget = (Node2D)GetParent(); paei.FireEvent(); }
private void MoveAlongPath(float distance) { //If the enemy is close to the target he stops moving if (((Node2D)GetParent()).Position.DistanceTo(target.Position) < 35) { if (!canAttack) { return; } //We set the path to null and the n break from the loop HitEvent hei = new HitEvent(); hei.attacker = (Node2D)GetParent(); hei.target = target; hei.damage = 5; hei.FireEvent(); canAttack = false; attackTimer.Start(); path = null; return; } //Stop the attack timer becuase the target has moved out of range attackTimer.Stop(); Vector2 startPoint = ((Node2D)GetParent()).Position; foreach (Vector2 point in path) { float distanceToNextPoint = startPoint.DistanceTo(point); if (distance <= distanceToNextPoint && distance >= 0.0f) { ((Node2D)GetParent()).Position = startPoint.LinearInterpolate(point, distance / distanceToNextPoint); break; } else if (distance < 0.0f) { SetProcess(false); break; } distance -= distanceToNextPoint; startPoint = point; path = path.Skip(1).ToArray(); } }
public void BodyEntered(Node node) { if (node.Name == "TileMap") { QueueFree(); } if (node.IsInGroup("Enemies")) { HitEvent hei = new HitEvent(); hei.target = (Node2D)node; hei.attacker = ((Node2D)GetParent().GetParent()); hei.damage = 10; hei.FireEvent(); QueueFree(); } }
public override void _PhysicsProcess(float delta) { if (!canFire) { return; } Physics2DDirectSpaceState worldState = GetWorld2d().DirectSpaceState; //Get the raycast hits and store them in a dictionary //This works, why?!?!???!?!?!?!! //Why does it not work on the child object, is it becuse the child object is not centered Godot.Collections.Dictionary hits = worldState.IntersectRay(parentNode.GlobalPosition, parentNode.GlobalPosition + parentNode.Transform.x * maxDistance, new Godot.Collections.Array { hitBox }); //If there are no hits then we return out of the function if (hits.Count > 0) { Vector2 hitPos = (Vector2)hits["position"]; //Offset the start position of hte laser so that it looks like it is originating at the nozzle of the barrel laserBeam.SetPointPosition(0, ((Node2D)GetParent().GetParent()).Position); laserBeam.SetPointPosition(1, hitPos); BeamHitParticles.Emitting = true; BeamHitParticles.Position = hitPos; //Fire of the hit event HitEvent hei = new HitEvent(); hei.target = (Node2D)hits["collider"]; hei.attacker = (Node2D)GetParent(); hei.damage = 100; hei.FireEvent(); } else { BeamHitParticles.Emitting = false; //Works do not delete!!!!!!!!!!!!!!! //======================================== laserBeam.SetPointPosition(0, new Vector2(16, 0)); laserBeam.SetPointPosition(1, Position + Transform.x * maxDistance); //======================================== } }