private Actor CheckRayCollision(Actor3D actor3D, Ray ray, float distance) { //dont test for collision against yourself if (!Equals(actor3D)) { if (actor3D is CollidablePrimitiveObject collidableObject) { if (collidableObject.CollisionPrimitive.Intersects(ray, out float?distanceToObj)) { if (distanceToObj <= distance) { return(collidableObject); } } } else if (actor3D is CollidableZoneObject zoneObject) { if (zoneObject.CollisionPrimitive.Intersects(ray, out float?distanceToObj)) { if (distanceToObj <= distance) { return(zoneObject); } } } } return(null); }
//test for collision against a specific object private Actor CheckCollision(GameTime gameTime, Actor3D actor3D) { //dont test for collision against yourself - remember the player is in the object manager list too! if (this != actor3D) { if (actor3D is CollidablePrimitiveObject) { CollidablePrimitiveObject collidableObject = actor3D as CollidablePrimitiveObject; if (CollisionPrimitive.Intersects(collidableObject.CollisionPrimitive, Transform3D.TranslateIncrement)) { return(collidableObject); } } else if (actor3D is CollidableZoneObject) { CollidableZoneObject zoneObject = actor3D as CollidableZoneObject; if (CollisionPrimitive.Intersects(zoneObject.CollisionPrimitive, Transform3D.TranslateIncrement)) { return(zoneObject); } } } return(null); }
private Actor CheckCollision(GameTime gameTime, Actor3D actor3D, Vector3 translation) { if (!Equals(actor3D)) { if (actor3D is CollidablePrimitiveObject) { CollidablePrimitiveObject collidableObject = actor3D as CollidablePrimitiveObject; if (CollisionPrimitive.Intersects(collidableObject.CollisionPrimitive, translation)) { return(collidableObject); } } else if (actor3D is CollidableZoneObject) { CollidableZoneObject zoneObject = actor3D as CollidableZoneObject; if (CollisionPrimitive.Intersects(zoneObject.CollisionPrimitive, translation)) { return(zoneObject); } } } return(null); }