void body_Collision( ref CollisionEvent collisionEvent ) { Body body1 = collisionEvent.ThisShape.Body; if( !body1.Static ) DoForce( body1 ); Body body2 = collisionEvent.OtherShape.Body; if( !body2.Static ) DoForce( body2 ); }
public Collidable(Game game, Entity.Entity parent, CollisionType type, CollisionEvent e, int health, int damage, Collidable parentCollidable, BoundingBox boundingBox) : base(game, parent) { this.onCollision = e; this.type = type; this.health = health; this.damage = damage; children = new List<Collidable>(); parentCollidable.addChild(this); this.boundingBox = boundingBox; }
public Collidable(Game game, Entity.Entity parent, CollisionType type, CollisionEvent e, int health, int damage,Collidable parentCollidable, float range = 50.0f) : base(game, parent) { this.onCollision = e; this.type = type; this.health = health; this.damage = damage; children = new List<Collidable>(); parentCollidable.addChild(this); rangeSquared = range * range; }
public void Execute(CollisionEvent collisionEvent) { CollisionEvent.Details collisionEventDetails = default; var aHasDetails = false; var bHasDetails = false; if (collisionEventsReceiverPropertiesFromEntity .HasComponent(collisionEvent.EntityA)) { aHasDetails = collisionEventsReceiverPropertiesFromEntity[collisionEvent.EntityA] .UsesCollisionDetails; } if (collisionEventsReceiverPropertiesFromEntity .HasComponent(collisionEvent.EntityB)) { bHasDetails = collisionEventsReceiverPropertiesFromEntity[collisionEvent.EntityB] .UsesCollisionDetails; } if (aHasDetails || bHasDetails) { collisionEventDetails = collisionEvent.CalculateDetails(ref physicsWorld); } if (collisionEventBufferFromEntity.HasComponent(collisionEvent.EntityA)) { ProcessForEntity( collisionEvent.EntityA, collisionEvent.EntityB, collisionEvent.Normal, aHasDetails, collisionEventDetails ); } if (collisionEventBufferFromEntity.HasComponent(collisionEvent.EntityB)) { ProcessForEntity( collisionEvent.EntityB, collisionEvent.EntityA, collisionEvent.Normal, bHasDetails, collisionEventDetails ); } }
public override void OnCollision(CollisionEvent collisionEvent) { if (collisionEvent.CollisionSide == CollisionSide.FROM_RIGHT_SIDE) { _velocityComponent.velocity = _speed; ((RenderComponent)GetEntity().GetComponentOfType(typeof(RenderComponent))).image = "goomba_right.png"; } else if (collisionEvent.CollisionSide == CollisionSide.FROM_LEFT_SIDE) { _velocityComponent.velocity = -_speed; ((RenderComponent)GetEntity().GetComponentOfType(typeof(RenderComponent))).image = "goomba_left.png"; } }
public void Update(float deltaTime) { for (int i = 0; i < _entities.Count; i++) { PositionComponent positionComponent1 = (PositionComponent)_entities[i].GetComponentOfType(typeof(PositionComponent)); BoxCollisionComponent boxCollisionComponent1 = (BoxCollisionComponent)_entities[i].GetComponentOfType(typeof(BoxCollisionComponent)); for (int j = i + 1; j < _entities.Count; j++) { PositionComponent positionComponent2 = (PositionComponent)_entities[j].GetComponentOfType(typeof(PositionComponent)); BoxCollisionComponent boxCollisionComponent2 = (BoxCollisionComponent)_entities[j].GetComponentOfType(typeof(BoxCollisionComponent)); if (positionComponent2.position.X + boxCollisionComponent2.size.X > positionComponent1.position.X && positionComponent1.position.X + boxCollisionComponent1.size.X > positionComponent2.position.X && positionComponent2.position.Y + boxCollisionComponent2.size.Y > positionComponent1.position.Y && positionComponent1.position.Y + boxCollisionComponent1.size.Y > positionComponent2.position.Y) { // Collision detected CollisionSide collisionSide1 = CollisionSide.UNKNOWN; CollisionSide collisionSide2 = CollisionSide.UNKNOWN; if (!boxCollisionComponent1.isTrigger && !boxCollisionComponent2.isTrigger) { if (_entities[i].GetComponentOfType(typeof(VelocityComponent)) != null) { collisionSide1 = HandleCollision(_entities[i], positionComponent2, boxCollisionComponent2); } if (_entities[j].GetComponentOfType(typeof(VelocityComponent)) != null) { collisionSide2 = HandleCollision(_entities[j], positionComponent1, boxCollisionComponent1); } } // Create the CollisionEvent for entity 1 : CollisionEvent gameEvent1 = new CollisionEvent( _entities[i], _entities[j], collisionSide1); _gameEngine.GetEventManager().AddEvent(gameEvent1); // Create the CollisionEvent for entity 2 : CollisionEvent gameEvent2 = new CollisionEvent( _entities[j], _entities[i], collisionSide2); _gameEngine.GetEventManager().AddEvent(gameEvent2); } } } }
/// <summary> /// Determines what happens if the ICollidable getSetEntity is intersecting another entity's hitbox /// </summary> /// <param name="source">.</param> /// <param name="data">CollisionEvent which contains the entity being collided with</param> public virtual void newCollision(object source, CollisionEvent data) { ICollidable cRef = (ICollidable)getSetEntity; if (data.collidable is ISmartObject) { smartObj = (ISmartObject)data.collidable; smartObjCollide = true; } else if (data.collidable is ISmartStructure) { smartStruct = (ISmartStructure)data.collidable; smartStructCollide = true; if (cRef.getSetCenter.X < data.collidable.getSetCenter.X) { data.mtv.X *= -1; } if (cRef.getSetCenter.Y < data.collidable.getSetCenter.Y) { data.mtv.Y *= -1; } getSetMoveVector = data.mtv * (getSetSpeed); //mPos += getSetMoveVector; physicsCollide = true; //getSetSpeed *= 0.1f; } else { if (cRef.getSetCenter.X < data.collidable.getSetCenter.X) { data.mtv.X *= -1; } if (cRef.getSetCenter.Y < data.collidable.getSetCenter.Y) { data.mtv.Y *= -1; } getSetMoveVector = data.mtv * (getSetSpeed); //mPos += getSetMoveVector; physicsCollide = true; //getSetSpeed *= 0.1f; } }
public void Execute(CollisionEvent collisionEvent) { if (Collisions.HasComponent(collisionEvent.EntityA)) { Collisions[collisionEvent.EntityA].Add(new CollisionBuffer { entity = collisionEvent.EntityB }); } if (Collisions.HasComponent(collisionEvent.EntityB)) { Collisions[collisionEvent.EntityB].Add(new CollisionBuffer { entity = collisionEvent.EntityA }); } }
public bool Hit(UObject obj) { bool bRetVal = Hit(obj.Collider); if (bRetVal) { CollisionEventArgs e = new CollisionEventArgs { Who = obj }; CollisionEvent?.Invoke(this, e); obj.Collider.Hit(Owner); } return(bRetVal); }
public void UpdateData() { SpriteRenderer sR = GetComponent <SpriteRenderer>(); if (item != null) { sR.sprite = item.itemPicture; gameObject.name = item.name + "(" + System.Enum.GetName(typeof(Item.tag), item.Tag) + ")"; if (item.scriptItem != null) { @event = item.scriptItem.collisionEvent; } } }
private void EvaluateCollisionEvent(Collision collision, CollisionEvent eventType) { GameObject other = collision.gameObject; if (other.tag == "Untagged" || string.IsNullOrEmpty(other.tag)) { return; } if (OnUserEnter == null) { return; } OnUserEnter?.Invoke(other, eventType); }
public void Execute(CollisionEvent collisionEvent) { { Entity entityA = collisionEvent.Entities.EntityA; Entity entityB = collisionEvent.Entities.EntityB; if (destroyOnContactGroup.HasComponent(entityA)) { entityCommandBuffer.AddComponent <ToDestroyTag>(entityA); } if (destroyOnContactGroup.HasComponent(entityB)) { entityCommandBuffer.AddComponent <ToDestroyTag>(entityB); } } }
public override void Collision(object source, CollisionEvent args) { if (args.Entity == this && args.Wall == null) { if (!SecondEncounter) { Script.getInstance.BeginDialogue(lines); SecondEncounter = true; } else { Script.getInstance.SingleDialogue(RepeatedText); } } }
static CollisionEvent GetCollisionEvent() { CollisionEvent e; if (m_EventPool.Count > 0) { e = m_EventPool[0]; m_EventPool.RemoveAt(0); } else { e = new CollisionEvent(); } return(e); }
public override void Update(float dt) { // TODO: only handle entities with id > own id? foreach (var entity in GetEntitiesWithMask()) { if (entity.Collision.Static) { continue; } ref var transform = ref entity.Transform; // If moved, collision detect/resolve if ((transform.Position - transform.PreviousPosition).Length() > Constants.Epsilon) { ref var collision = ref entity.Collision; // Query StaticBVH var overlappingIds = Global.EntityManager.CollisionBvh.Query(transform, collision); // For each id: Collision resolve foreach (var id in overlappingIds) { if (id == entity.EntityId) { continue; } var otherEntity = Global.EntityManager.Entities[id]; var collisionData = CheckIntersection(entity, otherEntity); if (collisionData.Intersecting) { //if (!entity.Collision.Static) //{ // Move mesh back out of the static mesh transform.Position += new Float4(collisionData.Normal * collisionData.Depth); // Remove velocity in the direction of the collision normal ref var physicsComponent = ref entity.Physics; var counterVelocity = RyneMath.Project(physicsComponent.Velocity, new Float4(collisionData.Normal)); physicsComponent.Velocity -= counterVelocity; //} var collisionEvent = new CollisionEvent(entity.EntityId, id, collisionData); Events.PushEvent(collisionEvent); } }
public void Execute(CollisionEvent collisionEvent) { // Collision event is between a static and dynamic box. // Verify all data in the provided event struct. Assert.IsTrue(math.all(collisionEvent.AccumulatedImpulses >= float4.zero)); Assert.AreNotEqual(collisionEvent.BodyIndices.BodyAIndex, collisionEvent.BodyIndices.BodyBIndex); Assert.AreEqual(collisionEvent.ColliderKeys.ColliderKeyA.Value, ColliderKey.Empty.Value); Assert.AreEqual(collisionEvent.ColliderKeys.ColliderKeyB.Value, ColliderKey.Empty.Value); Assert.AreEqual(collisionEvent.Entities.EntityA, Bodies[collisionEvent.BodyIndices.BodyAIndex].Entity); Assert.AreEqual(collisionEvent.Entities.EntityB, Bodies[collisionEvent.BodyIndices.BodyBIndex].Entity); Assert.AreEqual(collisionEvent.Entities.EntityA.Version, 1); Assert.AreEqual(collisionEvent.Entities.EntityB.Version, 1); Assert.AreApproximatelyEqual(collisionEvent.Normal.x, 0.0f, 0.01f); Assert.AreApproximatelyEqual(collisionEvent.Normal.y, 1.0f, 0.01f); Assert.AreApproximatelyEqual(collisionEvent.Normal.z, 0.0f, 0.01f); }
public void Execute(CollisionEvent collisionEvent) { // Collision event is between a static and dynamic box. // Verify all data in the provided event struct. CollisionEvent.Details details = collisionEvent.CalculateDetails(ref World); Assert.IsTrue(details.EstimatedImpulse >= 0.0f); Assert.IsTrue(details.EstimatedContactPointPositions.Length == 4); Assert.AreNotEqual(collisionEvent.BodyIndexA, collisionEvent.BodyIndexB); Assert.AreEqual(collisionEvent.ColliderKeyA.Value, ColliderKey.Empty.Value); Assert.AreEqual(collisionEvent.ColliderKeyB.Value, ColliderKey.Empty.Value); Assert.AreEqual(collisionEvent.EntityA, Bodies[collisionEvent.BodyIndexA].Entity); Assert.AreEqual(collisionEvent.EntityB, Bodies[collisionEvent.BodyIndexB].Entity); Assert.AreApproximatelyEqual(collisionEvent.Normal.x, 0.0f, 0.01f); Assert.AreApproximatelyEqual(collisionEvent.Normal.y, 1.0f, 0.01f); Assert.AreApproximatelyEqual(collisionEvent.Normal.z, 0.0f, 0.01f); }
public override void Collision(object source, CollisionEvent args) { if (args.Entity == this && args.Wall != null) { mWalkDir *= -1; if (mPatrolVert == true) { mPosition.Y = mPrevPos.Y + (10 * mWalkDir); } else { mPosition.X = mPrevPos.X + (10 * mWalkDir); } } }
public void TakeDamage(float damage) { CurrentHealth = Mathf.Max(CurrentHealth - damage, 0.0f); if (CurrentHealth > 0) { var e = new CollisionEvent(); e.CurrentHealth = CurrentHealth; e.MaxHealth = MaxHealth; Messenger.Broadcast(e); } else { Messenger.Broadcast(new DeathEvent()); } }
private void body_Collision(ref CollisionEvent collisionEvent) { Body body1 = collisionEvent.ThisShape.Body; if (!body1.Static) { DoForce(body1); } Body body2 = collisionEvent.OtherShape.Body; if (!body2.Static) { DoForce(body2); } }
private void attachedParentBody_Collision(ref CollisionEvent collisionEvent) { if (lastJumpTime == 0) { return; } lastJumpTime = 0; Dynamic objDynamic = MapSystemWorld.GetMapObjectByBody( collisionEvent.OtherShape.Body) as Dynamic; if (objDynamic == null) { return; } Character unit = (Character)AttachedMapObjectParent; if (unit == null || unit.Intellect == null) { return; } //Not kick allies Unit objUnit = objDynamic.GetParentUnitHavingIntellect(); if (objUnit == null) { return; } if (objUnit.Intellect.Faction == unit.Intellect.Faction) { return; } objUnit.DoDamage(unit, unit.Position, collisionEvent.OtherShape, Type.NormalMode.Damage, true); SoundPlay3D(Type.SoundBlowKick, .5f, false); if (EntitySystemWorld.Instance.IsServer() && Type.NetworkType == EntityNetworkTypes.Synchronized) { Server_SendSoundPlayBlowKick(); } }
public override float HitTest(Ball.Ball ball, float dTime, CollisionEvent coll, PlayerPhysics physics) { if (!_data.IsEnabled) { return(-1.0f); } var lastFace = _mover.LastHitFace; // for effective computing, adding a last face hit value to speed calculations // a ball can only hit one face never two // also if a ball hits a face then it can not hit either radius // so only check these if a face is not hit // endRadius is more likely than baseRadius ... so check it first var hitTime = HitTestFlipperFace(ball, dTime, coll, lastFace); // first face if (hitTime >= 0) { return(hitTime); } hitTime = HitTestFlipperFace(ball, dTime, coll, !lastFace); //second face if (hitTime >= 0) { _mover.LastHitFace = !lastFace; // change this face to check first // HACK return(hitTime); } hitTime = HitTestFlipperEnd(ball, dTime, coll); // end radius if (hitTime >= 0) { return(hitTime); } hitTime = _mover.HitCircleBase.HitTest(ball, dTime, coll, physics); if (hitTime >= 0) { // Tangent velocity of contact point (rotate Normal right) // rad units*d/t (Radians*diameter/time) coll.HitVel.Set(0, 0); coll.HitMomentBit = true; return(hitTime); } return(-1.0f); // no hits }
public void OnUserEventHandler(GameObject other, CollisionEvent eventType) { switch (eventType) { case CollisionEvent.ENTER: connectedObject = other; onGameObject = true; beginTime = Time.time; break; case CollisionEvent.EXIT: connectedObject = null; onGameObject = false; elapsedTime = 0; break; } }
public void Execute(CollisionEvent collisionEvent) { if (collisions.Exists(collisionEvent.Entities.EntityA)) { collisions[collisionEvent.Entities.EntityA].Add(new CollisionBufferData() { entity = collisionEvent.Entities.EntityB }); } if (collisions.Exists(collisionEvent.Entities.EntityB)) { collisions[collisionEvent.Entities.EntityB].Add(new CollisionBufferData() { entity = collisionEvent.Entities.EntityA }); } }
/// <summary> /// Called when the projectile collides with an other object. /// </summary> /// <param name="e">The event-data.</param> public override void OnCollision(CollisionEvent e) { base.OnCollision(e); // do not consider collision if there is no collision but an intersection if (!game.Physics.CanSolidsCollide(e.ThisSolid, e.OtherSolid)) { return; } if (EnableExplosion) { OnExplosion(e.OtherSolid.UserData as ITransformable); } destroyNextUpdate = true; }
public void Execute(CollisionEvent collisionEvent) { var entityA = collisionEvent.EntityA; var entityB = collisionEvent.EntityB; var foodEntity = GetEntityFromComponentGroup(entityA, entityB, FoodGroup); if (foodEntity != Entity.Null) { var foodInstance = FoodGroup[foodEntity]; if (foodInstance.isLaunched) { foodInstance.playBouncingAudio = true; EntityCommandBuffer.SetComponent(foodEntity, foodInstance); } } }
/// <summary> /// Called when [collision]. /// </summary> /// <param name="e">The e.</param> public override void OnCollision(CollisionEvent e) { base.OnCollision(e); if (dying) // dont do anything when dying { return; } if (!game.Physics.CanSolidsCollide(e.ThisSolid, e.OtherSolid)) { return; } IGameObject collisionObject = e.OtherSolid.UserData as IGameObject; if (collisionObject == null) { return; } switch (collisionObject.ContactGroup) { case Engine.Physics.ContactGroup.PlayerProjectiles: if (collisionObject is IWeaponProjectile) { ReceiveDamage((collisionObject as IWeaponProjectile).Damage); } InfoMessage("Getroffen!"); break; case Engine.Physics.ContactGroup.Player: if (collisionObject is Player2) { OnDeath(); ((Player2)collisionObject).ReceiveDamage(20); } break; default: //InfoMessage("No Action for Collision Group: " + collisionObject.ContactGroup); break; } }
public void Execute(CollisionEvent collisionEvent) { Entity entityA = collisionEvent.Entities.EntityA; Entity entityB = collisionEvent.Entities.EntityB; bool isBodyATriggerCollider = TriggerColliderGroup.Exists(entityA); bool isBodyBTriggerCollider = TriggerColliderGroup.Exists(entityB); if (isBodyATriggerCollider) { SetCollidingTriggerCollider(entityA, entityB); } if (isBodyBTriggerCollider) { SetCollidingTriggerCollider(entityB, entityA); } }
private void TriggerCollisionEvent(Entity collideEntity, BoxSide side, int collideIndex) { var thisColAction = CollisionActions.FirstOrDefault(c => (c.Side == side || c.Side == BoxSide.All) && c.TargetTag == collideEntity.Tag); thisColAction?.Action.Invoke(thisColAction.ApplyActionOnCollider ? collideEntity : Entity); CollisionEvent?.Invoke(new CollisionData(Entity, collideEntity, side, collideIndex)); var collideComp = collideEntity.GetCurrentState().GetComponent <PhysicsComponent>(); var collideColAction = collideComp?.CollisionActions.FirstOrDefault(c => (c.Side == side.Inversed() || c.Side == BoxSide.All) && c.TargetTag == Entity.Tag); collideColAction?.Action.Invoke(collideColAction.ApplyActionOnCollider ? Entity : collideEntity); collideComp?.CollisionEvent?.Invoke(new CollisionData(collideEntity, Entity, side.Inversed(), collideIndex)); }
public void Execute(CollisionEvent collisionEvent) { Entity entityA = collisionEvent.Entities.EntityA; Entity entityB = collisionEvent.Entities.EntityB; //Solids will never affect themselves if (entityA != entityB) { bool isASolidAgent = SolidAgentGroup.Exists(entityA); bool isBSolidAgent = SolidAgentGroup.Exists(entityB); bool hasTranslationA = TranslationGroup.Exists(entityA); bool hasTranslationB = TranslationGroup.Exists(entityB); bool hasRotationA = TranslationGroup.Exists(entityA); bool hasRotationB = TranslationGroup.Exists(entityB); if (hasTranslationA && hasTranslationB && hasRotationA && hasRotationB) { //Entity A is a SolidAgent if (isASolidAgent) { RigidBody solidAgentRigidBody = World.Bodies[collisionEvent.BodyIndices.BodyAIndex]; RigidBody solidRigidBody = World.Bodies[collisionEvent.BodyIndices.BodyBIndex]; CollideWithSolid(entityA, entityB, ref solidAgentRigidBody, ref solidRigidBody); } //Entity B is a SolidAgent if (isBSolidAgent) { RigidBody solidAgentRigidBody = World.Bodies[collisionEvent.BodyIndices.BodyBIndex]; RigidBody solidRigidBody = World.Bodies[collisionEvent.BodyIndices.BodyAIndex]; CollideWithSolid(entityB, entityA, ref solidAgentRigidBody, ref solidRigidBody); } } } }
public bool Intersects(ICollider collider) { if (collider is Circle) { Circle a = this; Circle b = ((Circle)collider); float r = b._radius + a._radius; r *= r; float valueToCheck = ((b.Particle.Position.X - a.Particle.Position.X) * (b.Particle.Position.X - a.Particle.Position.X)) + ((b.Particle.Position.Y - a.Particle.Position.Y)) * ((b.Particle.Position.Y - a.Particle.Position.Y)); bool result = r >= valueToCheck; Colliding = result; if (Colliding) { // event 1 CollisionEvent args = new CollisionEvent(); args.Colliding = true; args.Entity1 = a.Owner.Owner; args.Entity2 = b.Owner.Owner; a.OnCollision(this, args); b.OnCollision(this, args); } return(result); } if (collider is RectangleCollider) { var rect = ((RectangleCollider)collider); var circleRect = new Rectangle( (int)Particle.Position.X - (int)_radius, (int)Particle.Position.Y - (int)_radius, (int)_radius * 2, (int)_radius * 2); return(circleRect.Intersects(rect.GetRectangle())); } return(false); }
public void Execute(CollisionEvent collisionEvent) { var entityA = collisionEvent.Entities.EntityA; var entityB = collisionEvent.Entities.EntityB; var playerEntity = GetEntityFromComponentGroup(entityA, entityB, PlayerGroup); var aiEntity = GetEntityFromComponentGroup(entityA, entityB, AIGroup); if (playerEntity != Entity.Null && aiEntity != Entity.Null) { var car = CarGroup[aiEntity]; if (!car.IsEngineDestroyed) { car.IsEngineDestroyed = true; car.PlayCrashAudio = true; } CarGroup[aiEntity] = car; } }
public override void OnCollision(CollisionEvent collisionEvent) { var hitEntity = collisionEvent.Source.OwnerEntity; if (hitEntity == Entity) { hitEntity = collisionEvent.Target.OwnerEntity; } if (hitEntity != null) { var ammoComponent = hitEntity.GetComponent <DefaultAmmo>(); if (hitEntity.HasComponent <Player>() || (ammoComponent != null && !ammoComponent.IsHostile)) { ProcessHit(); } } }
void Body_Collision( ref CollisionEvent collisionEvent ) { //Type.SoundCollision if( soundCollisionTimeRemaining == 0 && Type.SoundCollision != null ) { Body thisBody = collisionEvent.ThisShape.Body; Body otherBody = collisionEvent.OtherShape.Body; Vec3 velocityDifference = thisBody.LastStepLinearVelocity; if( !otherBody.Static ) velocityDifference -= otherBody.LastStepLinearVelocity; else velocityDifference -= thisBody.LinearVelocity; float minVelocity = Type.SoundCollisionMinVelocity; bool allowPlay = velocityDifference.LengthSqr() > minVelocity * minVelocity; if( allowPlay ) { SoundPlay3D( Type.SoundCollision, .5f, false ); soundCollisionTimeRemaining = .25f; if( EntitySystemWorld.Instance.IsServer() && Type.NetworkType == EntityNetworkTypes.Synchronized ) { Server_SendSoundPlayCollisionToAllClients(); } if( !soundCollisionTimeRemainingTimerAdded ) { AddTimer(); soundCollisionTimeRemainingTimerAdded = true; } } } //Type.ImpulseDamageCoefficient if( Type.ImpulseDamageCoefficient != 0 && Life > Type.LifeMin ) { Body thisBody = collisionEvent.ThisShape.Body; Body otherBody = collisionEvent.OtherShape.Body; float otherMass = otherBody.Mass; float impulse = 0; impulse += thisBody.LastStepLinearVelocity.LengthFast() * thisBody.Mass; if( otherMass != 0 ) impulse += otherBody.LastStepLinearVelocity.LengthFast() * otherMass; float damage = impulse * Type.ImpulseDamageCoefficient; if( damage >= Type.ImpulseMinimalDamage ) OnDamage( null, collisionEvent.Position, collisionEvent.ThisShape, damage, true ); } }
public CollisionEventData(ICollidable collidee, ICollidable collider, bool repeat, CollisionEvent evnt) { Collidee = collidee; Collider = collider; Event = evnt; Repeat = repeat; }
public void register(CollisionEvent aEnter, CollisionEvent aStay, CollisionEvent aExit) { m_Enter += aEnter; m_Stay += aStay; m_Exit += aExit; }
void attachedParentBody_Collision( ref CollisionEvent collisionEvent ) { if( lastJumpTime == 0 ) return; lastJumpTime = 0; Dynamic objDynamic = MapSystemWorld.GetMapObjectByBody( collisionEvent.OtherShape.Body ) as Dynamic; if( objDynamic == null ) return; Character unit = (Character)AttachedMapObjectParent; if( unit == null || unit.Intellect == null ) return; //Not kick allies Unit objUnit = objDynamic.GetIntellectedRootUnit(); if( objUnit == null ) return; if( objUnit.Intellect.Faction == unit.Intellect.Faction ) return; objUnit.DoDamage( unit, unit.Position, collisionEvent.OtherShape, Type.NormalMode.Damage, true ); SoundPlay3D( Type.SoundBlowKick, .5f, false ); }
/// <summary> /// Registers a collision between two video models, resulting in the delegate specified being called. /// </summary> /// <param name="one"></param> /// <param name="two"></param> /// <param name="collision"></param> public void RegisterCollision(VideoSprite collider, bool repeat, CollisionEvent collision) { collisions.Add(new CollisionEventData(this, collider, repeat, collision)); }
void magnetBody_Collision( ref CollisionEvent collisionEvent ) { Body mapObjectBody = collisionEvent.OtherShape.Body; MapObject mapObject = MapSystemWorld.GetMapObjectByBody( mapObjectBody ); if( mapObject == null ) return; if( mapObject == this ) return; if( IsMagnetBodyAttached( mapObjectBody ) ) return; int count; if( lastMagnetContactsCount.TryGetValue( mapObjectBody, out count ) ) lastMagnetContactsCount.Remove( mapObjectBody ); else count = 0; lastMagnetContactsCount.Add( mapObjectBody, count + 1 ); }
public void unregister(CollisionEvent aEnter, CollisionEvent aStay, CollisionEvent aExit) { m_Enter -= aEnter; m_Stay -= aStay; m_Exit -= aExit; }
void attachedParentBody_Collision( ref CollisionEvent collisionEvent ) { if( lastJumpTime == 0 ) return; lastJumpTime = 0; Dynamic objDynamic = MapSystemWorld.GetMapObjectByBody( collisionEvent.OtherShape.Body ) as Dynamic; if( objDynamic == null ) return; Character unit = (Character)AttachedMapObjectParent; if( unit == null || unit.Intellect == null ) return; //Not kick allies Unit objUnit = objDynamic.GetParentUnitHavingIntellect(); if( objUnit == null ) return; if( objUnit.Intellect.Faction == unit.Intellect.Faction ) return; objUnit.DoDamage( unit, unit.Position, collisionEvent.OtherShape, Type.NormalMode.Damage, true ); SoundPlay3D( Type.SoundBlowKick, .5f, false ); if( EntitySystemWorld.Instance.IsServer() && Type.NetworkType == EntityNetworkTypes.Synchronized ) { Server_SendSoundPlayBlowKick(); } }
private void body_Collision(ref CollisionEvent collisionEvent) { Body otherBody = collisionEvent.OtherShape.Body; if (HeightmapTerrain.GetTerrainByBody(otherBody) != null) return; if (otherBody.Static && otherBody.Name.Contains("Map")) //LDASH custom map names return; //Note: Incin ---- Dynamic_Collision needs to be removed Body thisBody = collisionEvent.ThisShape.Body; //if (!otherBody.Static) // DoForce(thisBody); if (otherBody == null && thisBody != null) DoForce(null, thisBody); if (!otherBody.Static) DoForce(otherBody, thisBody); //collisionEvent.Position, collisionEvent.Normal); float otherMass = otherBody.Mass; float impulse = 0; impulse += thisBody.LastStepLinearVelocity.Length() * thisBody.Mass; if (otherMass != 0) impulse += otherBody.LastStepLinearVelocity.Length() * otherMass; float damage = impulse; // *Type.ImpulseDamageCoefficient; MapObject mapobj = MapSystemWorld.GetMapObjectByBody(otherBody); if (mapobj != null) { Dynamic obj = mapobj as Dynamic; if (obj != null) { if (obj.Name.Contains("House")) { //damage house if (obj.Type.ImpulseDamageCoefficient != 0) { damage = impulse * obj.Type.ImpulseDamageCoefficient; } else { float health = obj.Health / 2; damage = health; } OnDamage(mapobj, collisionEvent.Position, collisionEvent.OtherShape, damage, true); //damage player if too fast if (Type.ImpulseDamageCoefficient != 0) damage = impulse * Type.ImpulseDamageCoefficient; else damage = impulse; //if minimal damage do player damage ////if (damage >= Type.ImpulseMinimalDamage) ////{ //// //OnDamage(null, collisionEvent.Position, collisionEvent.ThisShape, damage, true);//damage the other guy here //// OnDamage(null, collisionEvent.Position, collisionEvent.ThisShape, damage, true); ////} } else //still object type damage { if (obj.Type.ImpulseDamageCoefficient != 0) damage = impulse * obj.Type.ImpulseDamageCoefficient; else damage = impulse * 0.5f; OnDamage(mapobj, collisionEvent.Position, collisionEvent.OtherShape, damage, true); } } } //else //damage self //{ // //if (Type.ImpulseDamageCoefficient != 0) // // damage = impulse * Type.ImpulseDamageCoefficient; // //else // // damage = impulse; // //if (damage >= Type.ImpulseMinimalDamage) // //{ // // OnDamage(null, collisionEvent.Position, collisionEvent.ThisShape, damage, true); // //} //} }