public static CollisionResult WithAtPos( string[] types, ICollider collider, float x, float y ) { foreach (var type in types) { HashSet<ICollider> colliders; typeCache.TryGetValue(type, out colliders); if (colliders != null) { foreach (var col in colliders) { // @TODO check center distances for optimisation? or full quadtree? if (col.isActive() && col != collider) { var intersect = collider.Intersect(col, x, y); if (intersect.Intersect && (intersect.MinimumTranslation.x != 0 || intersect.MinimumTranslation.y != 0) ) { return intersect; } } } } } return new CollisionResult() { Intersect = false }; }
public override CollisionResult Intersect(ICollider col, float speedX, float speedY) { if (col is Hitbox) { var res = IntersectHitbox(col as Hitbox, speedX, speedY); return new CollisionResult() { Intersect = res.Intersect, MinimumTranslation = res.MinimumTranslation, Collider = col, CollisionObject = col.GetGameObject() }; } if (col is Polybox) { var res = IntersectPolybox(col as Polybox, speedX, speedY); return new CollisionResult() { Intersect = res.Intersect || res.WillIntersect, MinimumTranslation = res.MinimumTranslation, Collider = col, CollisionObject = col.GetGameObject() }; } Logging.Log("Collision type not supported for", this, col); return new CollisionResult() { Intersect = false }; }
public AGSCheckBox(string id, Resolver resolver) : base(id, resolver) { _uIEvents = AddComponent<IUIEvents>(); _skinComponent = AddComponent<ISkinComponent>(); _hasRoom = AddComponent<IHasRoom>(); _animationContainer = AddComponent<IAnimationContainer>(); _inObjectTree = AddComponent<IInObjectTree>(); _collider = AddComponent<ICollider>(); _visibleComponent = AddComponent<IVisibleComponent>(); _enabledComponent = AddComponent<IEnabledComponent>(); _customProperties = AddComponent<ICustomPropertiesComponent>(); _drawableInfo = AddComponent<IDrawableInfo>(); _hotspotComponent = AddComponent<IHotspotComponent>(); _shaderComponent = AddComponent<IShaderComponent>(); _translateComponent = AddComponent<ITranslateComponent>(); _imageComponent = AddComponent<IImageComponent>(); _scaleComponent = AddComponent<IScaleComponent>(); _rotateComponent = AddComponent<IRotateComponent>(); _pixelPerfectComponent = AddComponent<IPixelPerfectComponent>(); _textComponent = AddComponent<ITextComponent>(); _checkboxComponent = AddComponent<ICheckboxComponent>(); beforeInitComponents(resolver); InitComponents(); afterInitComponents(resolver); }
public AGSCharacter(string id, Resolver resolver, IOutfit outfit) : base(id, resolver) { _hasRoom = AddComponent<IHasRoom>(); _animationContainer = AddComponent<IAnimationContainer>(); _inObjectTree = AddComponent<IInObjectTree>(); _collider = AddComponent<ICollider>(); _visibleComponent = AddComponent<IVisibleComponent>(); _enabledComponent = AddComponent<IEnabledComponent>(); _customProperties = AddComponent<ICustomPropertiesComponent>(); _drawableInfo = AddComponent<IDrawableInfo>(); _hotspotComponent = AddComponent<IHotspotComponent>(); _shaderComponent = AddComponent<IShaderComponent>(); _transformComponent = AddComponent<ITranslateComponent>(); _imageComponent = AddComponent<IImageComponent>(); _scaleComponent = AddComponent<IScaleComponent>(); _rotateComponent = AddComponent<IRotateComponent>(); _pixelPerfectComponent = AddComponent<IPixelPerfectComponent>(); _faceDirectionBehavior = AddComponent<IFaceDirectionBehavior>(); _hasOutfit = AddComponent<IHasOutfit>(); _hasInventory = AddComponent<IHasInventory>(); _followBehavior = AddComponent<IFollowBehavior>(); beforeInitComponents(resolver, outfit); InitComponents(); afterInitComponents(resolver, outfit); }
public override void Init(IEntity entity) { base.Init(entity); _collider = entity.GetComponent<ICollider>(); _drawableInfo = entity.GetComponent<IDrawableInfo>(); _tree = entity.GetComponent<IInObjectTree>(); _visible = entity.GetComponent<IVisibleComponent>(); _enabled = entity.GetComponent<IEnabledComponent>(); _gameEvents.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute); }
public static void UnassignFromType(ICollider col, string type) { HashSet<ICollider> colliders; typeCache.TryGetValue(type, out colliders); if (colliders == null) { colliders = new HashSet<ICollider>(); typeCache.Add(type, colliders); } colliders.Remove(col); }
/// <summary> /// Devuelve si hay o no colisión entre dos nodos del grafo de escena /// que tengan un collider asociado /// </summary> /// <param name="vector">vector</param> /// <returns>longitud del vector</returns> public static bool Collision(ICollider lhs, ICollider rhs) { Collider colliderL = lhs.GetCollider(); Collider colliderR = rhs.GetCollider(); // los dos collider son rectangulos if (colliderL.IsCircle == false && colliderR.IsCircle == false) return ((ColliderRect)colliderL).Intersects(((ColliderRect)colliderR)); // TODO: interseccion entre otros colliders //else if (colliderL.IsCircle && colliderR.IsCircle) // los dos son círculos // return colliderL.Circle.Intersects(colliderL.Circle); //else if (!colliderL.IsCircle && colliderR.IsCircle) // return colliderR.Circle.Intersects(colliderL.Rectangle); //else // return colliderL.Circle.Intersects(colliderR.Rectangle); return false; }
public RaycastHit(Vector3 point, Vector3 normal, Vector3 barycentricCoordinate, float distance, int triangleIndex, Vector2 textureCoord, Vector2 textureCoord2, Vector2 lightmapCoord, IGameObject hit, ICollider collider) : this() { this.point = point; this.normal = normal; this.barycentricCoordinate = barycentricCoordinate; this.distance = distance; this.triangleIndex = triangleIndex; this.textureCoord = textureCoord; this.textureCoord2 = textureCoord2; this.lightmapCoord = lightmapCoord; this.hit = hit; this.collider = collider; }
public bool CanCollideWith(ICollider collider) { return(collider is BallData); }
/// <summary> /// Registers a new collider with the component. Will check to be /// sure the collider isn't already on the list. /// </summary> /// <param name="collider">The collider to add</param> void ICollisionService.RegisterCollider(ICollider collider) { //Check if the collider has been previously registered if (!(_allColliders.Contains(collider))) _allColliders.Add(collider); }
public Color ProcessCollision(HRender render, ICollider collider, HRay ray) { return(Shader(render, collider, ray)); }
public override void Setter(ICollider target, in RectF bounds)
public void HandleUsableItemCollision(ICollider collider) { }
public void HandleDoorCollision(ICollider collider) { }
public virtual CollisionResult Intersect(ICollider col, float speedX, float speedY) { return new CollisionResult() { Intersect = false }; }
private bool DiscreteCD(ICollider[] obj1Colliders,Vector3 obj1Pos, ICollider obj2Collider, Vector3 obj2Pos) { bool collision = false; //Get obj2 colliders center pos in world cords not objectCord Vector3 obj2colliderPos = obj2Collider.m_Centre.ReturnAddVector(obj2Pos); foreach (ICollider obj1Collider in obj1Colliders) { //Get obj1 colliders center pos in world cords not objectCord Vector3 obj1colliderPos = obj1Collider.m_Centre.ReturnAddVector(obj1Pos); if (obj1Collider.m_Size!=null) { //two boxes if (obj2Collider.m_Size!=null) { return BoxBoxCollision(obj1colliderPos, obj1Collider.m_Size, obj2colliderPos, obj2Collider.m_Size); } // box and sphere else if (obj2Collider.m_Radius.HasValue) { return SphereBoxCollision(obj1colliderPos, obj2Collider.m_Radius.Value, obj1colliderPos, obj2Collider.m_Size); } } else if (obj1Collider.m_Radius.HasValue) { //sphere and box if (obj2Collider.m_Size!=null) { return SphereBoxCollision(obj1colliderPos, obj1Collider.m_Radius.Value, obj2colliderPos, obj2Collider.m_Size); } //Two spheres else if (obj2Collider.m_Radius.HasValue) { return SphereSphereCollision(obj1colliderPos, obj1Collider.m_Radius.Value, obj2colliderPos, obj2Collider.m_Radius.Value); } } } return collision; }
/// <summary> /// Removes a collider from the list of registered colliders. /// </summary> /// <param name="collider">The collider to remove</param> void ICollisionService.DeregisterCollider(ICollider collider) { _allColliders.Remove(collider); }
/// <summary> /// Checks two objects to see if a collision has occured /// </summary> /// <param name="obj1">First ICollider object</param> /// <param name="obj2">Second ICollider object</param> /// <returns>True if a collision has occured, false otherwise</returns> bool ICollisionService.CheckCollision(ICollider obj1, ICollider obj2) { return this.CheckCollision(obj1, obj2); }
public static CollisionResult WithAtPos( string type, ICollider collider, float x, float y ) { return WithAtPos (new string[] {type}, collider, x, y); }
public static CollisionResult With(string[] types, ICollider collider ) { return WithAtPos (types, collider, collider.GetPosition().x, collider.GetPosition().y); }
public static CollisionResult With(string type, ICollider collider ) { return WithAtPos (new string[] {type}, collider, collider.GetPosition().x, collider.GetPosition().y); }
private void HandleGenericCollision(ICollider collider) { }
public void BindCollider(ICollider collider) { _collider = collider; }
public void HandleEnemyCollision(ICollider collider) { }
/// <summary> /// Checks two objects to see if a collision has occured /// </summary> /// <param name="obj1">First ICollider object</param> /// <param name="obj2">Second ICollider object</param> /// <returns>True if a collision has occured, false otherwise</returns> public bool CheckCollision(ICollider obj1, ICollider obj2) { //If either object is not collidable return false if (!(obj1.IsColliable && obj2.IsColliable)) return false; if (obj1.CollideType == ColliderType.Circle) { if (obj2.CollideType == ColliderType.Circle) { //A collision occurs if the distance between the two centers is less than //the sum of their radii return (Vector2.Distance(obj1.Center, obj2.Center) < (obj1.Norm + obj2.Norm)); } } //Default value return false; }
public void HandlePickupItemCollision(ICollider collider) { }
//On collision with a game object public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider) { }
public void HandleSwordCollision(ICollider collider) { }
public void Shooting(MilitaryUnit sender, ICollider shootingAt, GameTime gametime) { mBehavior.Shooting(sender, shootingAt, gametime); }
public void HandleWallCollision(ICollider collider) { HandleGenericCollision(collider); }
private void SetAttackTarget(ICollider attackPosition) { mShouldAttack = true; mAttackPosition = attackPosition; }
public void OnCollide(ICollider collider) { Collide?.Invoke(new ColliderEventArgs { Collider = collider }); }
//Whether this collider is colliding with the given collider abstract public bool CollidingWith(ICollider otherCollider);
public VertexCollider(Vector2 position, ICollider parent) { this.position = position; this.parent = parent; }
public void CollisionWith(ICollider other) { }
/// <summary> /// Devuelve un par ordenado, es decir, el nodo con HashID más bajo delente /// </summary> /// <param name="lhs">Primer Collider</param> /// <param name="rhs">Segundo Collider</param> /// <returns>un objeto tipo pair de SceneNode ordenados</returns> public static Tuple<Scenes.SceneNode,Scenes.SceneNode> GetSortedPair(ICollider lhs, ICollider rhs) { return (lhs.GetHashCode() > rhs.GetHashCode()) ? new Tuple<Scenes.SceneNode, Scenes.SceneNode>((Scenes.SceneNode)rhs, (Scenes.SceneNode)lhs) : new Tuple<Scenes.SceneNode, Scenes.SceneNode>((Scenes.SceneNode)lhs, (Scenes.SceneNode)rhs); }
public override CollisionResult Intersect(ICollider col, float speedX, float speedY) { if (col is Hitbox) { return IntersectHitbox(col as Hitbox, speedX, speedY); } if (col is Polybox) { return IntersectPolybox(col as Polybox, speedX, speedY); } Logging.Log("Collision type not supported for", this, col); return new CollisionResult() { Intersect = false }; }
public bool IsCollidableCase(ICollider collider, int i, int j) => IsCollidableCaseDelegate(collider, Grid[i, j]);
public void AddDynamicCollider(IDynamic dynamic, ICollider col) //dynamic is a separate interface //adds a dynamic collider to the scene { colliderList.Add(col); dynamicList.Add(dynamic); }
private void AddCollider(RigidActor actor, ICollider collider) { if (collider is AggregateCollider agg) { foreach (var c in agg.ColliderComponents) { AddCollider(actor, c); } } else if (collider is TriangleMeshCollider triCollider) { var desc = triCollider.GetDescriptor(GetMaterialIndices); // Avoiding offline cook path for now because // 1. Comments in Physx.Net imply memory leak using streams // 2. I don't want to deal with disk caching cooks yet var finalMesh = this.physxPhysics.CreateTriangleMesh(cooker, desc); var meshGeom = new TriangleMeshGeometry(finalMesh); RigidActorExt.CreateExclusiveShape(actor, meshGeom, globalMaterials, null); } else if (collider is TriangleModelCollider triModelCollider) { foreach (var mesh in triModelCollider.MeshColliders) { var desc = mesh.GetDescriptor(GetMaterialIndices); // Avoiding offline cook path for now because // 1. Comments in Physx.Net imply memory leak using streams // 2. I don't want to deal with disk caching cooks yet var finalMesh = this.physxPhysics.CreateTriangleMesh(cooker, desc); var meshGeom = new TriangleMeshGeometry(finalMesh); RigidActorExt.CreateExclusiveShape(actor, meshGeom, globalMaterials, null); } } else if (collider is IVertexBasedCollider vertCollider) { var desc = new ConvexMeshDesc() { Flags = ConvexFlag.ComputeConvex }; desc.SetPositions(vertCollider.GetTransformedVertices()); var mesh = this.physxPhysics.CreateConvexMesh(this.cooker, desc); var geom = new ConvexMeshGeometry(mesh); var mat = this.GetOrCreateMaterial(vertCollider.PhysicsMaterial); // TODO: re-use shared shapes instead of creating exclusive RigidActorExt.CreateExclusiveShape(actor, geom, mat); } else if (collider is ConvexModelCollider modelCollider) { foreach (var verts in modelCollider.Meshes) { var desc = new ConvexMeshDesc() { Flags = ConvexFlag.ComputeConvex }; desc.SetPositions(verts); var mesh = this.physxPhysics.CreateConvexMesh(this.cooker, desc); var geom = new ConvexMeshGeometry(mesh); var mat = this.GetOrCreateMaterial(modelCollider.PhysicsMaterial); // TODO: re-use shared shapes instead of creating exclusive RigidActorExt.CreateExclusiveShape(actor, geom, mat); } } }
public Item(ICollider c, Velocity2 v) { Collider = c; Velocity = v; }
public void Shooting(MilitaryUnit sender, ICollider shootingAt, GameTime gametime) { if (shootingAt == null) { return; } // make sure to active the AI if it wasn't already because something is shooting // (either getting shot at or shooting at smth) if (!mActive) { mActive = true; } // now check whether your units fired or you get attacked by the enemy, we don't really need to do anything if // we're not the ones shooting var asEnemy = sender as EnemyUnit; if (asEnemy == null) { return; } var senderAsFast = sender as EnemyFast; var senderAsHeavy = sender as EnemyHeavy; var targetAsPlatform = shootingAt as PlatformBlank; if (senderAsFast != null) { // the one who shot was a scouting unit, make sure to retreat ASAP Retreat(senderAsFast, EEnemyType.Scout, gametime); // at this point we know that our scout attacked an enemy platform if (targetAsPlatform != null) { // make sure to not attack the center, since then the unit wouldn't even move there since there's collision. // this basically sets the position to attack for the AI if it decides to attack. SetAttackTarget(targetAsPlatform); } return; } if (senderAsHeavy != null) { // a defending unit shot, thus move (currently all) defending units to where this happened var allDefendings = GetPrioritiyQueueByEnemyType(EEnemyType.Defend).ToList(); // make a temporary flocking group to reduce stress foreach (var defending in allDefendings) { if (mIsCurrentlyMoving[defending.GetObject()]) { continue; } if (!mUnitToFlockingGroup.ContainsKey(defending.GetObject())) { mUnitToFlockingGroup[defending.GetObject()] = mDirector.GetMilitaryManager.GetNewFlock(); mUnitToFlockingGroup[defending.GetObject()].AssignUnit(defending.GetObject()); } mUnitToFlockingGroup[defending.GetObject()].FindPath(shootingAt.Center); } SetAttackTarget(shootingAt); return; } // now the unit is defintely an attacking one, make sure to retreat once the target is destroyed. if (shootingAt.Health > 0) { SetAttackTarget(shootingAt); return; } mShouldAttack = false; Retreat(asEnemy, EEnemyType.Attack, gametime); }
public NPCCollisionHandler(INPC npc, float colliderWidth, float colliderHeight, float offsetX, float offsetY) { this.npc = npc; Collider = new BoxCollider(npc, colliderWidth, colliderHeight, offsetX, offsetY); }
//Whether this collider is colliding with the given collider public override bool CollidingWith(ICollider otherCollider) { //The result bool result = false; //Get the bounds of this box double maximumX = position.x + size.x / 2; double maximumY = position.y + size.y / 2; double minimumX = position.x - size.x / 2; double minimumY = position.y - size.y / 2; //The other collider extracted as a box collider BoxCollider otherBoxCollider; //The other collider extracted as a circle collider CircleCollider otherCircleCollider; //If the other collider is a box collider if (otherCollider is BoxCollider) { //Get the other collider as a box collider otherBoxCollider = (BoxCollider)otherCollider; //Get the bounds of the other box double maximumOtherX = otherBoxCollider.position.x + otherBoxCollider.size.x / 2; double maximumOtherY = otherBoxCollider.position.y + otherBoxCollider.size.y / 2; double minimumOtherX = otherBoxCollider.position.x - otherBoxCollider.size.x / 2; double minimumOtherY = otherBoxCollider.position.y - otherBoxCollider.size.y / 2; //If x intervals are intersecting if (maximumX > minimumOtherX && minimumX < maximumOtherX) { //If y intervals are intersecting if (maximumY > minimumOtherY && minimumY < maximumOtherY) { //Mark as colliding result = true; } } } else if (otherCollider is CircleCollider) { //Get the other colllider as a circle collider otherCircleCollider = (CircleCollider)otherCollider; //Get the circle's position Vector2 circlePosition = otherCircleCollider.Position; //If circle's center is diagonal to this collider if ((circlePosition.x < minimumX || circlePosition.x > maximumX) && (circlePosition.y < minimumY || circlePosition.y > maximumY)) { //Get the squared radius of the circle collider double radiusSquared = otherCircleCollider.Radius * otherCircleCollider.Radius; //Get the four corners of the box Vector2 upperLeft = new Vector2(minimumX, minimumY); Vector2 upperRight = new Vector2(maximumX, minimumY); Vector2 lowerLeft = new Vector2(minimumX, maximumY); Vector2 lowerRight = new Vector2(maximumX, maximumY); //Get the corner's distances to the circle double distanceUpperLeftSquared = otherCircleCollider.Position.distanceToSquared(upperLeft); double distanceUpperRightSquared = otherCircleCollider.Position.distanceToSquared(upperRight); double distanceLowerLeftSquared = otherCircleCollider.Position.distanceToSquared(lowerLeft); double distanceLowerRightSquared = otherCircleCollider.Position.distanceToSquared(lowerRight); //If any of the corners are within range if (distanceUpperLeftSquared < radiusSquared) { //Mark as colliding result = true; } else if (distanceUpperRightSquared < radiusSquared) { //Mark as colliding result = true; } else if (distanceLowerLeftSquared < radiusSquared) { //Mark as colliding result = true; } else if (distanceLowerRightSquared < radiusSquared) { //Mark as colliding result = true; } } //If circle's center is lateral to this collider else { //Get the bounding box of the circle BoxCollider bounds = otherCircleCollider.bounds; //If colliding with bounding box if (CollidingWith(bounds)) { //Mark as colliding result = true; } } } //Return result return(result); }
public void HandleBlockCollision(ICollider collider) { HandleGenericCollision(collider); }
public DoorCollisionHandler(IGameObject doors, float colliderWidth, float colliderHeight, float offsetX, float offsetY) { this.door = doors; Collider = new BoxCollider(doors, colliderWidth, colliderHeight, offsetX, offsetY); }
public void HandleEnemyCollision(ICollider collider) { // Should enemies collide with eachother? }
public void HandleBlockCollision(ICollider collider) { }
public void HandlePlayerCollision(ICollider collider) { HandleGenericCollision(collider); }
public void HandlePlayerCollision(ICollider collider) { }
private bool ContinuousCD(ICollider[] obj1Colliders, Vector3 obj1Pos, ICollider obj2Collider, Vector3 obj2Pos) { bool collision = false; return collision; }