Exemplo n.º 1
0
    void FixedUpdate()
    {
        float delta = Time.fixedDeltaTime;

        CheckForTarget();
        ForceManager.ApplyAllForces(delta);
    }
Exemplo n.º 2
0
    public override void UpdateForce(ref PhysicsDataPtr pData, float dt)
    {
        if (id1 == null)
        {
            ForceManager.DeleteForceGenerator(this);
        }

        //TODO LINK UP TO ID THROUGH STATIC CLASS
        PhysicsDataPtr obj = id1.mpPhysicsData;

        float yPos   = obj.pos.y;
        float yForce = 0;

        if (yPos >= liquidPlaneY + maxDepth)
        {
            return;
        }
        else if (yPos <= liquidPlaneY - maxDepth)
        {
            yForce = objectVolume * liquidDensity;
        }
        else
        {
            yForce = liquidDensity * objectVolume * (yPos - maxDepth - liquidPlaneY) / (2 * maxDepth);
        }

        Vector2 force = new Vector2(0.0f, Mathf.Abs(yForce));

        obj.accumulatedForces += force;

        id1.mpPhysicsData = obj;
    }
Exemplo n.º 3
0
    private void SetSpringForce(string touchedObjectName)
    {
        //Get Touched Object initial position
        Vector3 initialPosition;

        try{
            initialPosition = dict[touchedObjectName];
        }
        catch (KeyNotFoundException e) {
            return;
        }
        //Scale position to workspace relative position and mm dimensions
        float   multiplier      = 333f;
        Vector3 touchedPosition = initialPosition * multiplier;

        //Get current cursor position
        Vector3 cursorPosition = GameObject.Find("Cursor").transform.position;

        //Get forces direction
        Vector3 forward = initialPosition - cursorPosition;

        //Set spring anchor point and direction effect
        float[] position  = new float[] { touchedPosition.x, touchedPosition.y, touchedPosition.z };
        float[] direction = new float[] { forward.x, forward.y, forward.z };

        //Constant gain and variable magnitude
        float gain      = 0.2f;
        float magnitude = GetSpringMagnitude(initialPosition, cursorPosition);

        Debug.Log("Resorte: " + magnitude);

        //Start spring force
        ForceManager.SetEnvironmentForce(ForceManager.SPRING, SPRING_INDEX, position, direction, gain, magnitude, 0, 0);
    }
Exemplo n.º 4
0
    private void SetFrictionForce(string touchedObjectName)
    {
        //Get Touched Object initial position
        Vector3 initialPosition;

        try{
            initialPosition = dict[touchedObjectName];
        }
        catch (KeyNotFoundException e) {
            return;
        }
        //Get current cursor position
        Vector3 cursorPosition = GameObject.Find("Cursor").transform.position;

        //Get forces direction
        Vector3 forward = initialPosition - cursorPosition;

        //Set friction anchor point and direction effect
        float[] position  = new float[] { initialPosition.x, initialPosition.y, initialPosition.z };
        float[] direction = new float[] { forward.x, forward.y, forward.z };

        //Constant gain and magnitude
        float gain      = 0.2f;
        float magnitude = GetFrictionMagnitude(initialPosition, cursorPosition);

        Debug.Log("Friccion: " + magnitude);

        //Start friction force
        ForceManager.SetEnvironmentForce(ForceManager.FRICTION, FRICTION_INDEX, position, direction, gain, magnitude, 0, 0);
    }
Exemplo n.º 5
0
        void Dispatch(bool emit)
        {
            Profiler.BeginSample("Dispatch loop");
            PartEmitter.UpdateParticleBursts();

            BindParticles();

            if (emit)
            {
                PartEmitter.UpdatePlayEvent();
            }

            if (!NoSimulation)
            {
                //Dispatch the update kernel.
                SetPariclesToKernel(ComputeShader, UpdateAllKernel);

                Profiler.BeginSample("Main update");
                ComputeShader.Dispatch(UpdateAllKernel, DispatchCount, 1, 1);
                Profiler.EndSample();

                ColliderManager.Dispatch();
                ForceManager.Dispatch();
            }


            Profiler.EndSample();
        }
Exemplo n.º 6
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Exemplo n.º 7
0
    //Collision detection
    void OnCollisionEnter(Collision collision)
    {
        //Haptic properties of the object we are colliding with
        HapticProperties props = collision.gameObject.GetComponentInChildren <HapticProperties>();

        //Get Stiffness
        float stiffness = props.stiffness;

        //Set friction or viscosity effect
        string type;

        if (stiffness >= maxStiffness)
        {
            type = ForceManager.FRICTION;
        }
        else
        {
            type = ForceManager.VISCOSITY;
        }

        //Get current cursor position
        Vector3 cursorPosition = GameObject.Find("Cursor").transform.position;

        //Set friction anchor point and direction effect
        float[] position  = new float[] { cursorPosition.x, cursorPosition.y, cursorPosition.z };
        float[] direction = new float[] { -cursorPosition.x, -cursorPosition.y, -cursorPosition.z };

        //Constant gain and magnitude
        float gain = 0.2f;

        ForceManager.SetEnvironmentForce(type, forceIndex, position, direction, gain, stiffness, 0, 0);
        Debug.Log("Force started with index " + forceIndex);
    }
Exemplo n.º 8
0
    public override void UpdateForce(ref PhysicsDataPtr pData, float dt)
    {
        if (object1 == null || object2 == null)
        {
            ForceManager.DeleteForceGenerator(this);
        }


        Vector2 pos1 = object1.mpPhysicsData.pos;
        Vector2 pos2 = object2.mpPhysicsData.pos;

        Vector2 diff = pos1 - pos2;
        float   dist = diff.magnitude;

        float magnitude = restLength - dist;

        //if (magnitude < 0.0f)
        //magnitude = -magnitude;
        magnitude *= springConstant;

        diff.Normalize();
        diff *= magnitude;

        object1.mpPhysicsData.accumulatedForces += diff;
        object2.mpPhysicsData.accumulatedForces -= diff;
    }
 //SetParticles does a global set, so you can be sure all kernels neccesary for updating use the right memory.
 protected void BindParticles()
 {
     Manager.Bind();
     Emitter.Bind();
     ForceManager.Bind();
     ColliderManager.Bind();
 }
Exemplo n.º 10
0
 // Use this for initialization
 private void Start()
 {
     gravityMultiplied = gravity * gravityMultiplier;
     CustomCollider[] colliders = FindObjectsOfType <CustomCollider>();
     collisionManager = new CollisionManager(colliders);
     RigidBodyScript[] rbs = FindObjectsOfType <RigidBodyScript>();
     forceManager = new ForceManager(rbs);
 }
Exemplo n.º 11
0
 private void Awake()
 {
     if (!instance)
     {
         instance = this;
         forces   = new List <ForceGenerator2D>();
     }
 }
Exemplo n.º 12
0
        protected override void Initialize()
        {
            forceManager    = new ForceManager();
            particleManager = new ParticleManager();
            broadPhase      = new BroadPhase();

            base.Initialize();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a new PhysicsVolume.
        /// </summary>
        /// <param name="id">The ID of the PhysicsVolume.</param>
        /// <param name="area">The area that when something
        /// is in, will be affected by the PhysicsVolume.</param>
        public PhysicsVolume(string id, Rectangle area)
        {
            this.id = id;

            collide             = new CollisionObject(id + "Collide", area);
            collide.OnCollided += new CollisionEvent(Collide);

            ForceManager.AddForce(this);
        }
Exemplo n.º 14
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start");
        instance = this;

        generator = GetComponent <BouyancyGenerator>();
        generator.SetShouldEffectAll(true);
        ForceManager.AddGenerator(generator);
    }
Exemplo n.º 15
0
    private bool deleteFlag = false;     // 合体中で、移動が終わり次第削除すべきかどうか


    void Start()
    {
        gridInfo     = transform.parent.GetComponent <GridInfo>();
        forceManager = GameObject.Find("ForceManager").GetComponent <ForceManager>();

        // デバッグ用
        //SetStartPos(2, 2);
        //targetPos = new Vector2Int(2, 4);
    }
Exemplo n.º 16
0
    void Fire()
    {
        if (weaponChoice < particlePrefabs.Count)
        {
            GameObject projectile = Instantiate(particlePrefabs[weaponChoice], transform.position, transform.rotation);
            projectile.GetComponent <Particle2D>().mpPhysicsData.vel = projectile.transform.up * projectile.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;

            BouyancyForceGenerator2D bfg = new BouyancyForceGenerator2D(projectile.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg);
        }
        else if (weaponChoice == particlePrefabs.Count)
        {
            GameObject projectile1 = Instantiate(particlePrefabs[0], transform.position, transform.rotation);
            projectile1.GetComponent <Particle2D>().mpPhysicsData.vel = projectile1.transform.up * projectile1.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            GameObject projectile2 = Instantiate(particlePrefabs[0], transform.position, transform.rotation);
            projectile2.GetComponent <Particle2D>().mpPhysicsData.vel = projectile2.transform.up * projectile2.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            Vector3 tmp = (projectile2.transform.up * projectile2.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude);
            projectile2.GetComponent <Particle2D>().mpPhysicsData.pos  = projectile2.transform.position;
            projectile2.GetComponent <Particle2D>().mpPhysicsData.pos += new Vector2(tmp.x, tmp.y).normalized * 4.0f;
            projectile2.transform.position = projectile2.GetComponent <Particle2D>().mpPhysicsData.pos;

            SpringForceGenerator2D fg = new SpringForceGenerator2D(projectile1.GetComponent <Particle2D>(), projectile2.GetComponent <Particle2D>(), 1, 2);
            ForceManager.AddForceGenerator(fg);
            BouyancyForceGenerator2D bfg1 = new BouyancyForceGenerator2D(projectile1.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg1);
            BouyancyForceGenerator2D bfg2 = new BouyancyForceGenerator2D(projectile2.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg2);
        }
        else
        {
            GameObject projectile1 = Instantiate(particlePrefabs[0], transform.position, transform.rotation);
            projectile1.GetComponent <Particle2D>().mpPhysicsData.vel = projectile1.transform.up * projectile1.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            GameObject projectile2 = Instantiate(particlePrefabs[0], transform.position, transform.rotation);
            projectile2.GetComponent <Particle2D>().mpPhysicsData.vel = projectile2.transform.up * projectile2.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            Vector3 tmp = projectile2.transform.up * projectile2.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            projectile2.GetComponent <Particle2D>().mpPhysicsData.pos  = projectile2.transform.position;
            projectile2.GetComponent <Particle2D>().mpPhysicsData.pos += new Vector2(tmp.x, tmp.y).normalized * 3.0f;
            projectile2.transform.position = projectile2.GetComponent <Particle2D>().mpPhysicsData.pos;

            //<<<<<<< Updated upstream
            RodForceGenerator2D fg = new RodForceGenerator2D(projectile1.GetComponent <Particle2D>(), projectile2.GetComponent <Particle2D>(), 10, 3);
            ForceManager.AddForceGenerator(fg);
            //=======
            //            RodForceGenerator2D fg = new RodForceGenerator2D();
            //            fg.startingObject1 = projectile1.GetComponent<Particle2D>();
            //            fg.startingObject2 = projectile2.GetComponent<Particle2D>();
            //            //ForceManager.AddForceGenerator(fg);
            //>>>>>>> Stashed changes

            BouyancyForceGenerator2D bfg1 = new BouyancyForceGenerator2D(projectile1.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg1);
            BouyancyForceGenerator2D bfg2 = new BouyancyForceGenerator2D(projectile2.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg2);
        }
    }
Exemplo n.º 17
0
 private void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         instance = this;
     }
 }
Exemplo n.º 18
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start");
        instance = this;

        particleManager = this.gameObject.AddComponent <ParticleManager>();
        generator       = GetComponent <BouyancyGenerator>();
        generator.SetShouldEffectAll(true);
        ForceManager.AddGenerator(generator);
        resolver = this.gameObject.AddComponent <ContactResolver>();
    }
Exemplo n.º 19
0
    // Start is called before the first frame update
    void Start()
    {
        PlanetaryForceGenerator.powerOfConstant = powerOfConstant;

        particleManager = GetComponent <ParticleManager>();
        foreach (Particle2D par in GameObject.FindObjectsOfType <Particle2D>())
        {
            particleManager.AddParticle(par);
            ForceManager.AddForceGenerator(new PlanetaryForceGenerator(par));
        }
    }
Exemplo n.º 20
0
 void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
         DontDestroyOnLoad(this);
     }
 }
Exemplo n.º 21
0
    void CheckForTarget()
    {
        if (target == null)
        {
            Vector3 pos = new Vector3(Random.Range(xRange.x, xRange.y), Random.Range(yRange.x, yRange.y), 0);
            target = Instantiate(targetPrefab, pos, Quaternion.identity);

            ForceManager.DeleteForceGenerator(bfg);
            bfg = new BouyancyForceGenerator2D(target.GetComponent <Particle2D>(), 1.0f, 0.5f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg);
        }
    }
Exemplo n.º 22
0
 public void Awake()
 {
     mForceManager = new ForceManager();
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
     RespawnTarget();
 }
Exemplo n.º 23
0
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance == this)
        {
            Destroy(gameObject);
        }

        AddBuoyancyForceGenerator(GameManager.instance.waterHeight, GameManager.instance.liquidDensity);
    }
Exemplo n.º 24
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(this.gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
     mIntegrator      = GetComponent <Integrator>();
     mForceManager    = GetComponent <ForceManager>();
     mParticleManager = GetComponent <Particle2DManager>();
 }
Exemplo n.º 25
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            Vector3 origin  = Camera.main.ScreenToWorldPoint(Input.mousePosition, Camera.MonoOrStereoscopicEye.Mono);
            Vector3 changeZ = new Vector3(origin.x, origin.y, asteroid.transform.position.z);

            //Instantiate(asteroid).transform.position = changeZ;
            //GetComponent<ParticleManager>().AddParticle(asteroid.GetComponent<Particle2D>());
            //ForceManager.AddForceGenerator(new PlanetaryForceGenerator(asteroid.GetComponent<Particle2D>()));

            GameObject obj = Instantiate(asteroid);
            obj.transform.position = changeZ;
            GetComponent <ParticleManager>().AddParticle(obj.GetComponent <Particle2D>());
            ForceManager.AddForceGenerator(new PlanetaryForceGenerator(obj.GetComponent <Particle2D>()));
        }
    }
Exemplo n.º 26
0
    private int delayCounterFinish; // 勝負がついた後すぐにシーン遷移すると、片方がゲーム画面に残されてしまうので、それを防ぐカウンター

    void Start()
    {
        myMaxHP    = 2500;
        rivalMaxHP = 2500;
        myHP       = myMaxHP;
        rivalHP    = rivalMaxHP;

        myHPChanger    = GameObject.Find("Canvas/MyHP").GetComponent <HPChanger>();
        rivalHPChanger = GameObject.Find("Canvas/RivalHP").GetComponent <HPChanger>();

        myHPChanger.SetMaxHP(myMaxHP);
        rivalHPChanger.SetMaxHP(rivalMaxHP);

        forceManager = GameObject.Find("ForceManager").GetComponent <ForceManager>();

        delayCounterFinish = -1;
    }
Exemplo n.º 27
0
    public void GenerateRandomParticle()
    {
        float x = Random.Range(-Camera.main.orthographicSize, Camera.main.orthographicSize);
        float y = Random.Range(-Camera.main.orthographicSize * Camera.main.aspect,
                               Camera.main.orthographicSize * Camera.main.aspect);
        GameObject newPar = Instantiate(particlePrefab, new Vector3(x, y, 0), Quaternion.identity);
        float      angle  = Random.Range(0.0f, 360.0f);

        newPar.GetComponent <Particle2D>().mpPhysicsData.vel = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0.0f)
                                                               * newPar.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;

        PlanetaryForceGenerator pfg = new PlanetaryForceGenerator(newPar.GetComponent <Particle2D>());

        ForceManager.AddForceGenerator(pfg);

        AddParticle(newPar.GetComponent <Particle2D>());

        //Vector2.Dot(new Vector2(), new Vector2());
    }
Exemplo n.º 28
0
    public static void MakeProjectile(Transform trans, GameObject type)
    {
        GameObject projectile = Instantiate(type, trans.position, trans.rotation);
        Vector3    direction  = Vector3.right;
        float      angle      = trans.eulerAngles.z * Mathf.Deg2Rad;
        float      sin        = Mathf.Sin(angle);
        float      cos        = Mathf.Cos(angle);

        Vector3 forward = new Vector3(
            direction.x * cos - direction.y * sin,
            direction.x * sin + direction.y * cos,
            0f);



        projectile.GetComponent <Particle2D>().Create(1, forward, new Vector2(0, -.01f), 0.999f, 10, unitID);
        particleList.Add(projectile);
        unitID += 1;
        if (type.name.Contains("Spring"))
        {
            GameObject projectile2 = Instantiate(type, trans.position, trans.rotation);
            projectile2.GetComponent <Particle2D>().Create(1, forward, new Vector2(0, -.01f), 0.999f, 1, unitID);
            particleList.Add(projectile2);
            unitID += 1;
            SpringGenerator newGenerator = new SpringGenerator();
            newGenerator.SetShouldEffectAll(false);
            ForceManager.AddGenerator(newGenerator);
            newGenerator.SetID(projectile.GetComponent <Particle2D>().GetID(), projectile2.GetComponent <Particle2D>().GetID());
        }
        else if (type.name.Contains("Rod"))
        {
            GameObject projectile2 = Instantiate(type, trans.position, trans.rotation);
            projectile2.GetComponent <Particle2D>().Create(1, forward, new Vector2(0, -.01f), 0.999f, 2, unitID);
            particleList.Add(projectile2);
            unitID += 1;
            Particle2DLink newLink = new Particle2DLink();
            newLink.id1 = projectile.GetComponent <Particle2D>().GetID();
            newLink.id2 = projectile2.GetComponent <Particle2D>().GetID();

            linkList.Add(newLink);
        }
    }
        void Dispatch(bool emit)
        {
            Profiler.BeginSample("Simulation loop");
            Emitter.UpdateForDispatch();

            BindParticles();

            if (emit)
            {
                Emitter.UpdatePlayEvent(m_prevSystemTime);
                m_prevSystemTime = SystemTime;
            }

            if (!NoSimulation)
            {
                Profiler.BeginSample("Pre Extenions update");
                if (OnPreSimulationCallback != null)
                {
                    OnPreSimulationCallback();
                }
                Profiler.EndSample();

                Profiler.BeginSample("Main update");
                DispatchExtensionKernel(ComputeShader, UpdateAllKernel);
                Profiler.EndSample();

                Profiler.BeginSample("Post Extenions update");
                if (OnPostSimulationCallback != null)
                {
                    OnPostSimulationCallback();
                }
                Profiler.EndSample();

                ColliderManager.Dispatch();
                ForceManager.Dispatch();
            }

            Profiler.EndSample();
        }
    // Update is called once per frame

    public override void UpdateForce(ref PhysicsDataPtr pData, float dt)
    {
        if (mPlanet == null)
        {
            ForceManager.DeleteForceGenerator(this);
            return;
        }

        Vector2 radiusVec = mPlanet.mpPhysicsData.pos - pData.pos;

        if (radiusVec.magnitude == 0)
        {
            return;
        }

        //radiusVec *= .5f;
        float gravitationalForce = (universalGavitationalConstant * (1 / mPlanet.mpPhysicsData.inverseMass) * (1 / pData.inverseMass)) / (radiusVec.magnitude * radiusVec.magnitude);

        radiusVec.Normalize();
        pData.accumulatedForces += gravitationalForce * radiusVec;
        //mPlanet.mpPhysicsData.accumulatedForces -= gravitationalForce * radiusVec;
    }