コード例 #1
0
        public void UpdateForce_WhenASpringIsCompressed_TheForceGeneratorAppliesAForceToTheEndOfTheSpring()
        {
            MockParticle.Setup(p => p.AddForce(new Vector3(4.5, 2.25, -4.5)));
            var forceGenerator = new SpringForceGenerator(MockOtherParticle.Object, 1.5, 13.5);

            forceGenerator.UpdateForce(MockParticle.Object, 1.0);
        }
コード例 #2
0
        public void UpdateForce_WhenABungeeIsExpanded_TheForceGeneratorAppliesAForceToTheEndOfTheBungee()
        {
            MockParticle.Setup(p => p.AddForce(new Vector3(-4.5, -2.25, 4.5)));
            var forceGenerator = new SpringForceGenerator(MockOtherParticle.Object, 1.5, 4.5, true);

            forceGenerator.UpdateForce(MockParticle.Object, 1.0);
        }
コード例 #3
0
		public void UpdateForce_WhenABungeeIsExpanded_TheForceGeneratorAppliesAForceToTheEndOfTheBungee()
		{
			MockParticle.Setup(p => p.AddForce(new Vector3(-4.5, -2.25, 4.5)));
			var forceGenerator = new SpringForceGenerator(MockOtherParticle.Object, 1.5, 4.5, true);

			forceGenerator.UpdateForce(MockParticle.Object, 1.0);
		}
コード例 #4
0
		public void UpdateForce_WhenASpringIsCompressed_TheForceGeneratorAppliesAForceToTheEndOfTheSpring()
		{
			MockParticle.Setup(p => p.AddForce(new Vector3(4.5, 2.25, -4.5)));
			var forceGenerator = new SpringForceGenerator(MockOtherParticle.Object, 1.5, 13.5);

			forceGenerator.UpdateForce(MockParticle.Object, 1.0);
		}
コード例 #5
0
    public ForceGenerator2D CreateSpringForceGenerator(GameObject object1, GameObject object2, float springConstant, float restLength)
    {
        GameObject           forceGenerator = new GameObject("SpringForceGenerator");
        SpringForceGenerator newGenerator   = forceGenerator.AddComponent <SpringForceGenerator>();

        newGenerator.Initialize(object1, object2, springConstant, restLength);
        AddForceGenerator(newGenerator);
        return(forceGenerator.GetComponent <ForceGenerator2D>());
    }
コード例 #6
0
ファイル: Fire.cs プロジェクト: iXiphos/GamePhysics
    void shootSpring()
    {
        float      speed   = 10.0f;
        Vector2    gravity = new Vector2(0.0f, -6.0f);
        GameObject proj    = Instantiate(projectile, gameObject.transform.position, gameObject.transform.rotation);
        Particle2D temp    = proj.GetComponent <Particle2D>();

        temp.Velocity     = transform.right * speed;
        temp.Acceleration = gravity;
        temp.Mass         = 1.0f;
        GameManager.Instance.mObjects.Add(temp);

        GameObject proj1 = Instantiate(projectile, gameObject.transform.position, gameObject.transform.rotation);

        temp              = proj1.GetComponent <Particle2D>();
        temp.Velocity     = transform.right * speed;
        temp.Acceleration = gravity;
        temp.Mass         = 3.0f;
        GameManager.Instance.mObjects.Add(temp);

        SpringForceGenerator springGenerator = new SpringForceGenerator(proj, proj1, 1.0f, 50.0f, true);

        GameManager.Instance.mForceManager.addForceGenerator(springGenerator);
    }
コード例 #7
0
    public void CreateProjectile(GameObject projectile, Transform spawnPoint, Transform playerPos)
    {
        float           speed = 0.0f;
        Vector2         angle = new Vector2(spawnPoint.position.x - playerPos.position.x, spawnPoint.position.y - playerPos.position.y);
        Vector2         gravity;
        PhysicsObject2D proj;
        GameObject      part;

        switch (mCurrentWeaponType)
        {
        case WeaponType.SPRING:
        {
            speed = 20.0f;
            float speed2 = 15.0f;
            gravity = new Vector2(0.0f, -6.0f);

            float mass1, mass2;
            mass1 = 1.0f;
            mass2 = 2.0f;

            part = Instantiate(projectile, spawnPoint.position, spawnPoint.rotation);
            mParticleManager.AddParticle(part.GetComponent <Particle2D>());
            proj = part.GetComponent <PhysicsObject2D>();
            proj.SetVel(angle * speed);
            proj.SetAcc(gravity);
            proj.SetInverseMass(mass1);
            proj.SetDamping(0.99f);
            mPhysicsObjects.Add(proj);

            PhysicsObject2D proj2;
            part  = Instantiate(projectile, spawnPoint.position - new Vector3(1.0f, 0.0f, 0.0f), spawnPoint.rotation);
            proj2 = part.GetComponent <PhysicsObject2D>();
            mParticleManager.AddParticle(part.GetComponent <Particle2D>());
            proj2.SetVel(angle * speed2);
            proj2.SetAcc(gravity);
            proj2.SetInverseMass(mass2);
            proj2.SetDamping(0.99f);
            mPhysicsObjects.Add(proj2);
            proj2.gameObject.AddComponent <DestroyOnExit>();

            SpringForceGenerator springForceGenerator = new SpringForceGenerator(proj, proj2, 1.0f, 50.0f, true);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(springForceGenerator);
            mForceManager.AddForceGenerator(springForceGenerator);
            BouyancyForceGenerator bGenerator = new BouyancyForceGenerator(true, proj, -6, 100, 0);
            mForceManager.AddForceGenerator(bGenerator);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator);
            bGenerator = new BouyancyForceGenerator(true, proj2, -6, 100, 0);
            mForceManager.AddForceGenerator(bGenerator);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator);
        }
        break;

        case WeaponType.ROD:
        {
            speed   = 30.0f;
            gravity = new Vector2(0.0f, -6.0f);

            proj = Instantiate(projectile, spawnPoint.position, spawnPoint.rotation).GetComponent <PhysicsObject2D>();
            proj.SetVel(angle * speed);
            proj.SetAcc(gravity);
            proj.SetInverseMass(1.0f);
            proj.SetDamping(0.99f);
            mPhysicsObjects.Add(proj);

            PhysicsObject2D proj2;
            proj2 = Instantiate(projectile, spawnPoint.position + new Vector3(2.5f, 0.0f), spawnPoint.rotation).GetComponent <PhysicsObject2D>();
            proj2.SetVel(angle * speed);
            proj2.SetAcc(gravity);
            proj2.SetInverseMass(1.0f);
            proj2.SetDamping(0.99f);
            mPhysicsObjects.Add(proj2);
            proj2.gameObject.AddComponent <DestroyOnExit>();

            Particle2DLink link = new ParticleRod(proj, proj2, 5.0f);
            AddParticleLink(link);

            BouyancyForceGenerator bGenerator = new BouyancyForceGenerator(true, proj, -6, 100, 0);
            mForceManager.AddForceGenerator(bGenerator);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator);
            bGenerator = new BouyancyForceGenerator(true, proj2, -6, 100, 0);
            mForceManager.AddForceGenerator(bGenerator);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator);
        }
        break;
        }
    }
コード例 #8
0
        public void UpdateForce_WhenABungeeIsCompressed_NoForceIsAppliedToTheEndOfTheBungee()
        {
            var forceGenerator = new SpringForceGenerator(MockOtherParticle.Object, 1.5, 13.5, true);

            forceGenerator.UpdateForce(MockParticle.Object, 1.0);
        }
コード例 #9
0
		public void UpdateForce_WhenABungeeIsCompressed_NoForceIsAppliedToTheEndOfTheBungee()
		{
			var forceGenerator = new SpringForceGenerator(MockOtherParticle.Object, 1.5, 13.5, true);

			forceGenerator.UpdateForce(MockParticle.Object, 1.0);
		}
コード例 #10
0
    void CreateProjectile(Projectiles projectileType, GameObject projectile)
    {
        switch (projectileType)
        {
        case Projectiles.PISTOL:
            projectile.transform.position = transform.position;
            projectile.GetComponent <Particle2D>().CreateParticle2D(2.0f, 0.99f, 10.0f, transform.right, projGravity, true);
            projectile.GetComponent <Particle2D>().setShouldIgnoreForces(false);

            BuoyancyForceGenerator buoyancy = new BuoyancyForceGenerator(projectile, projectile.transform.localScale.y / 2.0f, 1.0f, WaterObject.waterTopPos.y, 80.0f);
            ForceManager.instance.AddForceGen(buoyancy);

            projectile.GetComponent <Particle2D>().setParticleInstantiated(true);
            Debug.Log(currentProjectileType);
            break;

        case Projectiles.SPRINGSHOT:
            projectile.transform.position = transform.position;
            GameObject secondShot = Instantiate(projectile);
            Vector3    newPos     = new Vector3(0.0f, 2.0f, 0.0f);
            secondShot.transform.position = newPos;

            projectile.GetComponent <Particle2D>().CreateParticle2D(2.0f, 0.99f, 10.0f, transform.right, projGravity, true);
            secondShot.GetComponent <Particle2D>().CreateParticle2D(2.0f, 0.99f, 25.0f, transform.right, projGravity, true);
            projectile.GetComponent <Particle2D>().setShouldIgnoreForces(false);
            secondShot.GetComponent <Particle2D>().setShouldIgnoreForces(false);

            SpringForceGenerator springGen = new SpringForceGenerator(projectile, secondShot, 2.0f, 0.5f);
            ForceManager.instance.AddForceGen(springGen);

            BuoyancyForceGenerator springBuoy1 = new BuoyancyForceGenerator(projectile, projectile.transform.localScale.y / 2.0f, 1.0f, WaterObject.waterTopPos.y, 80.0f);
            ForceManager.instance.AddForceGen(springBuoy1);

            BuoyancyForceGenerator springBuoy2 = new BuoyancyForceGenerator(projectile, projectile.transform.localScale.y / 2.0f, 1.0f, WaterObject.waterTopPos.y, 80.0f);
            ForceManager.instance.AddForceGen(springBuoy2);

            projectile.GetComponent <Particle2D>().setParticleInstantiated(true);
            secondShot.GetComponent <Particle2D>().setParticleInstantiated(true);

            Debug.Log(currentProjectileType);
            break;

        case Projectiles.RODSHOT:
            projectile.transform.position = transform.position;
            GameObject connectedShot = Instantiate(projectile);
            Vector3    changePos     = new Vector3(0.0f, 2.0f, 0.0f);
            connectedShot.transform.position = changePos;
            projectile.GetComponent <Particle2D>().CreateParticle2D(2.0f, 0.99f, 10.0f, transform.right, projGravity, true);
            connectedShot.GetComponent <Particle2D>().CreateParticle2D(2.0f, 0.99f, 25.0f, transform.right, projGravity, true);
            projectile.GetComponent <Particle2D>().setShouldIgnoreForces(false);
            connectedShot.GetComponent <Particle2D>().setShouldIgnoreForces(false);

            ParticleRod newRod = new ParticleRod();
            newRod.InstantiateVariables(projectile.GetComponent <Particle2D>(), connectedShot.GetComponent <Particle2D>(), 10.0f);
            particleLinks.Add(newRod);

            BuoyancyForceGenerator rodBuoy1 = new BuoyancyForceGenerator(projectile, projectile.transform.localScale.y / 2.0f, 1.0f, WaterObject.waterTopPos.y, 80.0f);
            ForceManager.instance.AddForceGen(rodBuoy1);

            BuoyancyForceGenerator rodBuoy2 = new BuoyancyForceGenerator(projectile, projectile.transform.localScale.y / 2.0f, 1.0f, WaterObject.waterTopPos.y, 80.0f);
            ForceManager.instance.AddForceGen(rodBuoy2);

            projectile.GetComponent <Particle2D>().setParticleInstantiated(true);
            connectedShot.GetComponent <Particle2D>().setParticleInstantiated(true);
            Debug.Log(currentProjectileType);
            break;
        }
    }