void FixedUpdate() { ExplosionStrength = FindObjectOfType <ExplosionStrengthText>().slider.value; //Set Strength to be slider value ExplosionRadius = FindObjectOfType <ExplosionRadiusText>().slider.value; //Set radius to be slider value //THIS IS HOW YOU DO GRAVITY BUT OPPOSITE THIS REPELS THE OBJECTS ExplosionBounds = new BoundingCircle(Transformation.Translation, ExplosionRadius); //Set bounds of explosion Transformation = GetComponent <myTransformation>(); //Get Transformation component of object BoundingCircle Bounds = new BoundingCircle(new MyVector3(0, 0, 0), ExplosionRadius); //Bounds Of explosion Bounds = ExplosionBounds as BoundingCircle; //Set bounds to be xplosion bounds Bounds.CentrePoint = Transformation.Translation; //Make sure centre point is position of expplosion Object = FindObjectsOfType <MyPhysics>(); //Find all physic objects for (int i = 0; i < Object.Length; i++) { if (Bounds.Intersects(Object[i].Transformation.BoundObject)) { float Radius = float.MinValue; //Set radius to be minium value if (Object[i].Transformation.BoundObject is AABB) { AABB Box1 = Object[i].Transformation.BoundObject as AABB; //Get the object collision box if (Box1.MaxExtent.x > Radius) { Radius = Box1.MaxExtent.x; //Set radius to be max extent x } if (Box1.MaxExtent.y > Radius) { Radius = Box1.MaxExtent.y; //Set radius to be max extent y } if (Box1.MaxExtent.z > Radius) { Radius = Box1.MaxExtent.z; //Set radius to be max extent z } } if (Object[i].Transformation.BoundObject is BoundingCircle) { BoundingCircle Sphere1 = Object[i].Transformation.BoundObject as BoundingCircle; //Get the object bounding sphere Radius = Sphere1.Radius; //Set radius to be object radius } ExplosionForce = VectorMaths.VectorNormalized(Object[i].Transformation.Translation - Transformation.Translation) * ExplosionStrength; //Set force of explosion to be normalised of object postion - explosion position Object[i].Force += ExplosionForce; //Increase object force by explosion force CentreOfMass = Transformation.Translation; //SEt centre of mass to explosion point Distance = Object[i].Transformation.Translation - Transformation.Translation; //Distance from object to explosion Normalised = VectorMaths.VectorNormalized(Distance); //Normalised Distance ImpactPoint = Normalised * Radius; //Set impact point to be normalised * radius ExplosionTorque = VectorMaths.VectorCrossProduct(ExplosionForce, CentreOfMass - ImpactPoint); //Toorque os the cross product of explosion force and centre of mass - impact point Object[i].torque += ExplosionTorque; //Torque is increaess by explosion torque } } }
public override void ContactPoint(BoundingObject RHS, out MyVector3 Point) { Point = new MyVector3(0, 0, 0); if (RHS is AABB) { AABB Box1 = RHS as AABB; ContPoin(this, Box1, out Point); } if (RHS is BoundingCircle) { } }
public override bool Intersects(BoundingObject RHS) { if (RHS is AABB) { AABB Box1 = RHS as AABB; return(Collide(this, Box1)); } if (RHS is BoundingCircle) { BoundingCircle Sphere1 = RHS as BoundingCircle; return(Collide(this, Sphere1)); } return(false); }
public override void CollisionResolution(BoundingObject RHS, out MyVector3 Norm, out float Penetration) { Norm = new MyVector3(0, 0, 0); Penetration = float.MaxValue; if (RHS is AABB) { AABB Box2 = RHS as AABB; Resolve(this, Box2, out Norm, out Penetration); } if (RHS is BoundingCircle) { BoundingCircle Circle2 = RHS as BoundingCircle; Resolve(this, Circle2, out Norm, out Penetration); } }
static private BoundingObject[] CreateBoundingObjects(Thing thing, Vector2 Center, Vector2 Size, float rotationInDegress) { BoundingObject[] boundingObjects; if (thing != null) { boundingObjects = (BoundingObject[])thing.CrearBoundingObjects().Clone(); } else { boundingObjects = new BoundingObject[] { new BoundingRectangle(new Vector2(0, 0), Size, 0) } }; for (int i = 0; i < boundingObjects.Length; i++) { boundingObjects[i] = boundingObjects[i].RotateAndTranslate(rotationInDegress, Center); } return(boundingObjects); }
public override void ContactPoint(BoundingObject RHS, out MyVector3 Point) { Point = new MyVector3(0, 0, 0); }
public Tuple <GameDirector, Canvas, CollisionManager> makeGame(GraphicsDevice graphicsDevice, Controller controller) { xmlParser = new XMLParser("test.xml"); director = new GameDirector(); canvas = new Canvas(new SpriteBatch(graphicsDevice)); collisionManager = new CollisionManager(); Hitbox top = new CollidingRectangle(new Vector2(-50, -450), Vector2.Zero, graphicsDevice.Viewport.Width + 100, 50); Hitbox bottom = new CollidingRectangle(new Vector2(-50, graphicsDevice.Viewport.Height + 50), Vector2.Zero, graphicsDevice.Viewport.Width + 100, 50); Hitbox left = new CollidingRectangle(new Vector2(-100, -450), Vector2.Zero, 50, graphicsDevice.Viewport.Height + 500); Hitbox right = new CollidingRectangle(new Vector2(graphicsDevice.Viewport.Width + 50, -450), Vector2.Zero, 50, graphicsDevice.Viewport.Height + 500); BoundingObject bTop = new BoundingObject(null, Vector2.Zero, canvas); BoundingObject bBottom = new BoundingObject(null, Vector2.Zero, canvas); BoundingObject bLeft = new BoundingObject(null, Vector2.Zero, canvas); BoundingObject bRight = new BoundingObject(null, Vector2.Zero, canvas); bTop.Hitbox = top; bBottom.Hitbox = bottom; bLeft.Hitbox = left; bRight.Hitbox = right; collisionManager.addToTeam(bTop, TEAM.UNASSIGNED); collisionManager.addToTeam(bBottom, TEAM.UNASSIGNED); collisionManager.addToTeam(bLeft, TEAM.UNASSIGNED); collisionManager.addToTeam(bRight, TEAM.UNASSIGNED); try { graphicsLoader = GraphicsLoader.makeGraphicsLoader(graphicsDevice); } catch (ArgumentException) { graphicsLoader = GraphicsLoader.getGraphicsLoader(); } EnemyFactory enemyFactory = new EnemyFactory(); xmlParser.Parse(); List <Encounter> encounters = xmlParser.getEncounterList(); foreach (var encounter in encounters) { EncounterEvent encounterEvent = new EncounterEvent(collisionManager, canvas, encounter, director); //Console.WriteLine(encounter.timeInMS); director.addEvent(encounter.timeInMS, encounterEvent); } SCREEN_WIDTH = graphicsDevice.Viewport.Bounds.Width; SCREEN_HEIGHT = graphicsDevice.Viewport.Bounds.Height; int offset = 50; Vector2 topMiddle = new Vector2(SCREEN_WIDTH / 2 - offset, -100); Vector2 topLeft = new Vector2(SCREEN_WIDTH / 4 - offset, -100); Vector2 topRight = new Vector2(3 * SCREEN_WIDTH / 4 - offset, -100); // sin.healthbar = new HealthBar(sin.Location, new Vector2(8, 0), 85, 90, sin.Health); Player player = MakePlayer(controller); player.invulnerable = hasCheatMode; director.addEvent(0, new PlayerEnter(canvas, player)); player.DeathEvent += canvas.OnPlayerDeath; return(new Tuple <GameDirector, Canvas, CollisionManager>(director, canvas, collisionManager)); }
public abstract void CollisionResolution(BoundingObject RHS, out MyVector3 Norm, out float Penetration); //For Resoloution I handle them as AABB Objects, this makes working out the penetration easier and less cpu intensive public abstract bool Intersects(BoundingObject RHS);
public abstract void CollisionResolution(BoundingObject RHS, out MyVector3 Norm, out float Penetration); //For Resoloution I handle them as AABB Objects, this makes working out the penetration easier and less cpu intensive
public abstract void ContactPoint(BoundingObject RHS, out MyVector3 Point);