void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args) { // We'll watch for RigidBody collisions RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs == null) { return; } if (bodyArgs.CollideWith.GetComponent <EnemyComponent>() != null) { Client.combatScene(GameRes.Data.Sprites.Desert_Material, this.PlayerParty, bodyArgs.CollideWith.GetComponent <EnemyComponent>().Creatures); } /*else if (bodyArgs.CollideWith.GetComponent<NPCComponent>() != null) * { * Client.combatScene(GameRes.Data.Sprites.Desert_Material, this.PlayerParty, bodyArgs.CollideWith.GetComponent<NPCComponent>().Creatures); * }*/ else { return; } bodyArgs.CollideWith.Active = false; bodyArgs.CollideWith.DisposeLater(); }
void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs.OtherShape.Parent.BodyType == BodyType.Static) { return; } float time = (float)Time.GameTimer.TotalSeconds; if (time - this.lastHitTime < 0.5f) { return; } this.lastHitTime = time; if (args.CollisionData.NormalImpulse > 50.0f) { this.Score(true); this.HitNotAnEnemy(); RigidBody other = bodyArgs.OtherShape.Parent; other.ApplyWorldImpulse(args.CollisionData.Normal * 1000); } }
public void OnCollisionBegin(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs rigidBodyArgs = args as RigidBodyCollisionEventArgs; if (rigidBodyArgs != null && rigidBodyArgs.OtherShape.IsSensor) { return; } PlayerController player = args.CollideWith.GetComponent <PlayerController>(); if (player != null) { if (Weapon != null) { foreach (GameObject child in player.GameObj.Children) { if (child.GetComponent <WeaponController>() != null) { Scene.RemoveObject(child); break; } } GameObject weapon = Weapon.Res.Instantiate(args.CollideWith.Transform.Pos, args.CollideWith.Transform.Angle); weapon.Parent = args.CollideWith; Scene.AddObject(weapon); } Scene.RemoveObject(GameObj); } }
void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs == null) { return; } if (bodyArgs.OtherShape.IsSensor) { return; } Transform myTransform = this.GameObj.Transform; RigidBody otherBody = bodyArgs.OtherShape.Parent; // Apply an impulse at the (world-space) position of the collision Vector2 impulseDirection = bodyArgs.CollisionData.Normal; Vector2 applyWorldPos = bodyArgs.CollisionData.Pos; otherBody.ApplyWorldImpulse( impulseDirection * 100.0f, applyWorldPos); // Display a log to note that we did so VisualLogs.Default .DrawVector(new Vector3(applyWorldPos), impulseDirection * 15.0f) .KeepAlive(1000.0f); }
void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs == null) { return; } if (bodyArgs.CollideWith.GetComponent <Wall>() != null) { speed *= -1.0f; } }
void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs.MyShape.IsSensor) { return; } if (bodyArgs.OtherShape.IsSensor) { return; } float impactStrength = bodyArgs.CollisionData.NormalImpulse / (4.0f * bodyArgs.MyShape.Parent.Mass); this.NotifyHit(MathF.Pow(impactStrength, 1.5f)); }
public void OnCollisionBegin(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs rigidBodyArgs = args as RigidBodyCollisionEventArgs; if (rigidBodyArgs != null && rigidBodyArgs.OtherShape.IsSensor) { return; } DamageHandler hit = args.CollideWith.GetComponent <DamageHandler>(); if (hit != null) { hit.Health -= Damage; } Scene.RemoveObject(GameObj); }
void ICmpCollisionListener.OnCollisionEnd(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs.MyShape.IsSensor) { // Ignore collisions with parent objects if (this.GameObj.IsChildOf(bodyArgs.OtherShape.Parent.GameObj)) { return; } // Keep track of all active collisions this.triggerCounter--; if (this.triggerCounter == 0) { this.OnTriggerDeactivated(); } } }
void ICmpCollisionListener.OnCollisionEnd(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs == null) { return; } if (bodyArgs.OtherShape.IsSensor) { return; } Bullet otherBullet = bodyArgs.CollideWith.GetComponent <Bullet>(); int spikeIndex = this.GetSpikeIndex(bodyArgs.MyShape); if (spikeIndex != -1 && otherBullet == null) { this.spikeState[spikeIndex].ContactCount--; } }
void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs == null) { return; } if (bodyArgs.OtherShape.IsSensor) { return; } Bullet otherBullet = bodyArgs.CollideWith.GetComponent <Bullet>(); int spikeIndex = this.GetSpikeIndex(bodyArgs.MyShape); if (spikeIndex != -1 && otherBullet == null) { this.spikeState[spikeIndex].ContactCount++; } if (this.state != MindState.Asleep) { if (spikeIndex != -1) { if (this.spikeState[spikeIndex].OpenValue > 0.75f && otherBullet == null) { this.FireExplosives(); } } else { if (otherBullet != null) { this.BlinkSpikes(MathF.Rnd.NextFloat(0.5f, 1.0f)); this.BlinkEye(MathF.Rnd.NextFloat(0.35f, 0.6f)); } } } }
void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs.MyShape.IsSensor) { // Ignore collisions with parent objects if (this.GameObj.IsChildOf(bodyArgs.OtherShape.Parent.GameObj)) { return; } // Keep track of all active collisions this.triggerCounter++; if (this.triggerCounter == 1) { this.OnTriggerActivated(); } // Display a visual log which shape triggered Rect shapeBounds = bodyArgs.MyShape.AABB; Vector2 shapePos = shapeBounds.Center; float shapeRadius = shapeBounds.WithOffset(-shapePos).BoundingRadius; VisualLog.Default .DrawCircle(new Vector3(shapePos), shapeRadius) .AnchorAt(this.GameObj) .KeepAlive(2000.0f); VisualLog.Default .DrawText( new Vector3(shapePos) - (shapeRadius + 10.0f) * Vector3.UnitY, bodyArgs.MyShape.UserTag == 1 ? "Right" : "Left") .Align(Alignment.Bottom) .AnchorAt(this.GameObj) .KeepAlive(2000.0f); } }
void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args) { // Ignore collisions with other sensors RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs.OtherShape.IsSensor) { return; } // Ignore collisions with the player bool isPlayer = args.CollideWith.GetComponent <PlayerShip>() != null; if (isPlayer) { return; } // Push the hit object a bit RigidBody body = this.GameObj.GetComponent <RigidBody>(); Transform transform = this.GameObj.Transform; RigidBody otherBody = args.CollideWith.GetComponent <RigidBody>(); otherBody.ApplyWorldImpulse(body.LinearVelocity * 2.0f, transform.Pos.Xy); // If it collided with an asteroid, apply damage Asteroid otherAsteroid = args.CollideWith.GetComponent <Asteroid>(); if (otherAsteroid != null) { otherAsteroid.DoDamage(this.damage); } // Get rid of the bullet this.GameObj.DisposeLater(); }
public void OnCollision(Component sender, RigidBodyCollisionEventArgs rgc) { }
void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args) { RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs; if (bodyArgs == null) { return; } if (bodyArgs.OtherShape.IsSensor) { return; } // Did we collide with a ship? If it's the same that fired the bullet, ignore this Ship otherShip = args.CollideWith.GetComponent <Ship>(); if (otherShip != null && otherShip.Owner == this.owner) { return; } // Get all the objet references we'll need RigidBody otherBody = args.CollideWith.RigidBody; Transform transform = this.GameObj.Transform; RigidBody body = this.GameObj.RigidBody; BulletBlueprint blueprint = this.blueprint.Res; // Okay, let's determine where *exactly* our bullet hit RayCastData firstHit; bool hitAnything = RigidBody.RayCast(transform.Pos.Xy - body.LinearVelocity * 2, transform.Pos.Xy + body.LinearVelocity * 2, data => { if (data.Shape.IsSensor) { return(-1.0f); } return(data.Fraction); }, out firstHit); Vector3 hitPos; float hitAngle; if (hitAnything) { hitPos = new Vector3(firstHit.Pos, 0.0f); hitAngle = (-firstHit.Normal).Angle; } else { // Note that it is possible for the raycast to not hit anything, // because it is essentially a line, while our bullet is wider than zero. hitPos = transform.Pos; hitAngle = transform.Angle; } // Push around whatever we've just hit and do damage, if it was a ship otherBody.ApplyWorldImpulse(body.LinearVelocity * MathF.Min(otherBody.Mass, blueprint.ImpactMass), transform.Pos.Xy); if (otherShip != null) { otherShip.DoDamage(blueprint.Damage); } // If we hit a part of the world, spawn the world hit effect if (otherShip == null && blueprint.HitWorldEffect != null) { GameObject effectObj = blueprint.HitWorldEffect.Res.Instantiate(hitPos, hitAngle); Scene.Current.AddObject(effectObj); } // Also spawn a generic hit effect in the color of the bullet if (blueprint.HitEffect != null) { GameObject effectObj = blueprint.HitEffect.Res.Instantiate(hitPos, hitAngle); ParticleEffect effect = effectObj.GetComponent <ParticleEffect>(); if (effect != null && this.owner != null) { ColorHsva color = this.owner.Color.ToHsva(); foreach (ParticleEmitter emitter in effect.Emitters) { emitter.MaxColor = emitter.MaxColor.WithSaturation(color.S).WithHue(color.H); emitter.MinColor = emitter.MinColor.WithSaturation(color.S).WithHue(color.H); } } Scene.Current.AddObject(effectObj); } // Play hit sounds if (blueprint.HitSound != null) { SoundInstance inst = DualityApp.Sound.PlaySound3D(blueprint.HitSound, hitPos); inst.Pitch = MathF.Rnd.NextFloat(0.95f, 1.05f); } HitSoundController otherHitSound = otherBody.GameObj.GetComponent <HitSoundController>(); if (otherHitSound != null) { otherHitSound.NotifyHit(MathF.Rnd.NextFloat(0.75f, 1.0f)); } // Delete the bullet this.GameObj.DisposeLater(); }