/// <summary> /// Setups the physics. The default directionf of this laser is pointing straight down!! 0 degrees is pointing straight down!! /// </summary> private void SetupPhysics() { if (body == null) { body = GetComponent <FSBodyComponent>().PhysicsBody; Vertices laserPoints = PolygonTools.CreateCapsule(length, width, edgeCount); laserPoints.Translate(new FVector2(0.0f, -(offsetRadius + length / 2.0f))); Fixture fix = body.CreateFixture(new PolygonShape(laserPoints, 1.0f)); CollisionPresets.SetAsEnemyShot(fix); body.OnCollision += OnCollisionEvent; } }
protected void SetupPhysics() { if (body == null) { body = GetComponent <FSBodyComponent>().PhysicsBody; shape = GetComponent <FSShapeComponent>().GetShape(); shape.Radius = minRadius; body.DestroyFixture(body.FixtureList[0]); body.CreateFixture(shape); CollisionPresets.SetFixtureCollision(body.FixtureList[0], collisionSetting); expansionRate = (maxRadius - minRadius) / expansionTime; gameObject.transform.localScale = new Vector3(2 * minRadius, 2 * minRadius, 1.0f); } body.IsSensor = true; body.GravityScale = 0.0f; //Explosions aren't affected by gravity body.OnCollision += OnCollisionEvent; }
// Update is called once per frame void FixedUpdate() { if (shape.Radius < maxRadius) { shape.Radius += expansionRate * Time.fixedDeltaTime; } else { shape.Radius = maxRadius; } body.DestroyFixture(body.FixtureList[0]); body.CreateFixture(shape); CollisionPresets.SetFixtureCollision(body.FixtureList[0], collisionSetting); gameObject.transform.localScale = new Vector3(2 * shape.Radius, 2 * shape.Radius, 1.0f); //print (shape.Radius); SetupPhysics(); lifeSpan -= Time.fixedDeltaTime; if (lifeSpan <= 0.0f) { GameObject.Destroy(gameObject); } }