Exemplo n.º 1
0
    private int DelayFollow()
    {
        int degree = 0;

        if (start == -1)
        {
            start++;
            startPlay = false;
        }
        record[start] = controller.transform.position;
        start++;
        if (start == dataNum)
        {
            startPlay = true;
            start     = 0;
        }
        if (startPlay)
        {
            attachPoint = record[start];
        }

        lengthToAttachPoint = (god.transform.position - attachPoint).magnitude;
        Vector3 _attachPoint = controller.transform.position + controller.transform.forward * lengthToAttachPoint;
        Vector3 direction    = _attachPoint - attachPoint;

        meshDeformer.AddDeformingForce(attachPoint - direction * 0.2f, direction.magnitude * deform);

        Vector3 crossUp        = Vector3.Cross(new Vector3(0, 1, 0), controller.transform.up);
        float   cos_sitaUp     = Vector3.Dot(crossUp, controller.transform.forward);
        float   rotationDegree = Vector3.Angle(new Vector3(0, 1, 0), controller.transform.up) * (cos_sitaUp < 0 ? -1 : 1);

        god.transform.forward  = attachPoint - pivot.transform.position;
        god.transform.position = pivot.transform.position + god.transform.forward * lengthToPivot;
        god.transform.Rotate(0, 0, rotationDegree);

        debugSphere.transform.position = attachPoint;
        _attachPoint = attachPoint + 0.1f * deform * direction;

        god2.transform.forward  = _attachPoint - pivot.transform.position;
        god2.transform.position = pivot.transform.position + god2.transform.forward * lengthToPivot;
        god2.transform.Rotate(0, 0, rotationDegree);

        Vector3 cross    = Vector3.Cross(controller.transform.forward, god.transform.forward);
        float   cos_sita = Vector3.Dot(controller.transform.forward, god.transform.forward);

        degree = (int)(Mathf.Acos(cos_sita) * 180 / Mathf.PI);

        // need to correct so that there's no degree when cut is just started

        /*if (!startPlay)
         * {
         *  degree = 0;
         * }*/

        return(degree);
    }
Exemplo n.º 2
0
    private void OnCollisionEnter(Collision collision)
    {
        float force = collision.impulse.magnitude;

        if (divideByMass)
        {
            force /= _rigidbody.mass;
        }
        foreach (ContactPoint contactPoint in collision.contacts)
        {
            Vector3 point = contactPoint.point - contactPoint.normal * Mathf.Max(contactPoint.separation, minForceOffset);
            _meshDeformer.AddDeformingForce(point, force);
        }
    }
Exemplo n.º 3
0
    public void HandleJumpDeformer()
    {
        float        force       = 900f;
        float        forceOffset = 0.1f;
        MeshDeformer deformer    = GetComponentInChildren <MeshDeformer>();

        if (deformer)
        {
            Vector3 point = transform.position - transform.up;
            point += transform.up * forceOffset;
            deformer.AddDeformingForce(point, -force / 3.0f);
            deformer.AddDeformingForce(point, force / 5.0f);
        }
    }
Exemplo n.º 4
0
 void OnCollisionEnter(Collision coll)
 {
     if (coll.gameObject.tag.Equals("Floor"))
     {
         mFloorTouched = true;
         if (mAudioSource != null && HitSound != null && coll.relativeVelocity.y > .5f)
         {
             mAudioSource.PlayOneShot(HitSound, coll.relativeVelocity.magnitude);
         }
     }
     else if (coll.gameObject.tag.Equals("Wall"))
     {
         MeshDeformer deformer = coll.collider.GetComponent <MeshDeformer>();
         if (deformer)
         {
             print("deform");
             Vector3 point = coll.GetContact(0).point;
             point += coll.GetContact(0).normal *forceOffset;
             deformer.AddDeformingForce(point, force);
         }
     }
     else
     {
         if (mAudioSource != null && HitSound != null && coll.relativeVelocity.magnitude > 2f)
         {
             mAudioSource.PlayOneShot(HitSound, coll.relativeVelocity.magnitude);
         }
     }
 }
Exemplo n.º 5
0
    private void OnCollisionEnter(Collision collision)
    {
        int i = 0;

        MeshDeformerInput.pressed = true;
        foreach (ContactPoint contact in collision.contacts)
        {
            i++;
            Debug.DrawRay(contact.point, contact.normal, Color.red);
            //meshDeformer.AddDeformingForce(contact.point, 10f);
            meshDeformer.AddDeformingForce(-contact.point, 50f);
        }
        Debug.Log(i);

        // DeformVertices();
    }
Exemplo n.º 6
0
    private void DeformPortalWithTransform(Transform otherTransform)
    {
        Vector3 convertedPoint = transform.InverseTransformPoint(otherTransform.position);

        if ((convertedPoint.z > 0) != triggerZDirection && Mathf.Abs(convertedPoint.z) > portalSwitchDistance)
        {
            triggerZDirection = (convertedPoint.z > 0);
            if (isDeforming)                // if we're not deforming before this, the user could have walked AROUND the portal.
            {
                SwitchDimensions();
            }
        }

        meshDeformer.AddDeformingForce(otherTransform.position, deformPower, triggerZDirection);
        isDeforming = true;
    }
Exemplo n.º 7
0
    public void WalkingCast()
    {
        RaycastHit hit;

        Debug.DrawLine(walkingCasterLeft.position, -walkingCasterLeft.right * 20, Color.magenta);
        if (Physics.Raycast(walkingCasterLeft.position, -walkingCasterLeft.right * 20, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * walkingForceOffset;
                deformer.AddDeformingForce(point, walkingForce);
            }
        }
        Debug.DrawLine(walkingCasterRight.position, walkingCasterRight.right * 20, Color.magenta);
        if (Physics.Raycast(walkingCasterRight.position, walkingCasterRight.right * 20, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * walkingForceOffset;
                deformer.AddDeformingForce(point, walkingForce);
            }
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (deformer)
     {
         sound_value = sound.UpdateVisual();
         deformer.AddDeformingForce(sound_value * 1000);     //the sound value is too small, so we need to amplify it, thus the 1000
         //deformer.AddDeformingForce(force);
     }
 }
Exemplo n.º 9
0
    void Update()
    {
        HandleInput();

        curMeshDeformers.Clear();
        for (int i = 0; i < meshforces.Count; i++)
        {
            Vector3[] normals = meshforces [i].Normals;
            Vector3   pos     = meshforces [i].transform.position;
            float     radius  = meshforces [i].Radius;
            for (int j = 0; j < normals.Length; j++)
            {
                RaycastHit[] hits;
                hits = Physics.RaycastAll(pos, normals [j], 1000f);

                for (int k = 0; k < hits.Length; k++)
                {
                    RaycastHit hit = hits [k];

                    if (hit.distance > radius)
                    {
                        continue;
                    }

                    //Debug.LogFormat ("hit {0}, {1}, {2}, {3}", hit.collider.name, hit.distance, hit.point, hit.normal);

                    MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer> ();
                    if (deformer != null)
                    {
                        deformer.AddDeformingForce(pos, normals [j], radius);
                        curMeshDeformers.Add(deformer);
                    }
                }
            }
        }

        //Debug.LogFormat (" last:{0} cur:{1}", lastMeshDeformers.Count, curMeshDeformers.Count);
        for (int i = 0; i < lastMeshDeformers.Count; i++)
        {
            if (curMeshDeformers.Contains(lastMeshDeformers [i]) == false)
            {
                lastMeshDeformers [i].ClearForce();
            }
        }

        lastMeshDeformers.Clear();
        for (int i = 0; i < curMeshDeformers.Count; i++)
        {
            lastMeshDeformers.Add(curMeshDeformers [i]);
        }

        for (int i = 0; i < lastMeshDeformers.Count; i++)
        {
            lastMeshDeformers [i].ResetVertices();
        }
    }
Exemplo n.º 10
0
    void OnCollisionStay(Collision col)
    {
        Vector3 point = col.contacts[0].point;

        point += col.contacts[0].normal * forceOffset;
        if (col.collider.gameObject.tag == "Web")
        {
            MeshDeformer deformer = col.collider.gameObject.GetComponent <MeshDeformer> ();
            deformer.AddDeformingForce(point, force);
        }
    }
Exemplo n.º 11
0
    void HandleInput()
    {
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            Vector3      point    = hit.point + hit.normal * forceOffset;
            deformer.AddDeformingForce(point, force);
        }
    }
Exemplo n.º 12
0
 // Update is called once per frame
 void Update()
 {
     if (TimeCount > 0 && deformFlag == true)
     {
         MeshDeformer deformer = this.gameObject.GetComponent <MeshDeformer>();
         if (deformer)
         {
             deformer.AddDeformingForce(forcePoint, force);
             TimeCount -= Time.deltaTime;
         }
     }
 }
    //OnCollisionStay method assures that the force is still appiled as long as the capsule keeps pushing on the same contact point
    void OnCollisionStay(Collision col)
    {
        MeshDeformer deformer = col.collider.GetComponent <MeshDeformer>();

        if (deformer)
        {
            for (int c = 0; c < col.contacts.Length; c++)
            {
                Vector3 point = col.contacts[c].point;
                point += col.contacts[c].normal * forceOffset;
                deformer.AddDeformingForce(point, force);
            }
        }
    }
Exemplo n.º 14
0
    public void ApplyDeformation(Collision collision)
    {
        MeshDeformer deformer = collision.collider.GetComponent <MeshDeformer>();

        if (deformer != null && collision.contacts.Length > 0)
        {
            Vector3 point = collision.contacts[0].point;
            point += collision.contacts[0].normal * deformationOffset;
            deformer.AddDeformingForce(point, deformationForce * rbody.velocity.magnitude);

            deathParticleSystem.transform.position = point;
            deathParticleSystem.Play();
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("death"))
        {
            GameManager.instance.PlayerDie();
            myrigidbody.angularVelocity = Vector3.zero;
            return;
        }

        int i = 0;

        MeshDeformerInput.pressed = true;
        foreach (ContactPoint contact in collision.contacts)
        {
            i++;
            Debug.DrawRay(contact.point, contact.normal, Color.red);
            //meshDeformer.AddDeformingForce(contact.point, 10f);
            meshDeformer.AddDeformingForce(-contact.point, 50f);
        }
        Debug.Log(i);

        // DeformVertices();
    }
Exemplo n.º 16
0
    public void LoseCast()
    {
        RaycastHit hit;

        // Debug.DrawLine(loseCaster.position, -loseCaster.up * 20, Color.magenta);
        if (Physics.Raycast(loseCaster.position, -loseCaster.up * 20, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * loseForceOffset;
                deformer.AddDeformingForce(point, loseForce);
            }
        }
    }
    public void HandleInput(Vector3 position, Vector3 direction, float radius)
    {
        Ray        inputRay = new Ray(position, direction);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * forceOffset;
                deformer.AddDeformingForce(point, force, radius);
            }
        }
    }
Exemplo n.º 18
0
    public static void HandleInput(float moreForce)
    {
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * forceOffset;
                deformer.AddDeformingForce(point, (force * moreForce));
            }
        }
    }
Exemplo n.º 19
0
    private void FixedUpdate()
    {
        RaycastHit hit;

        if (Physics.Raycast(raycast_point.position, -Vector3.up, out hit))
        {
            print("Found an object - distance: " + hit.distance);
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * forceOffset;
                deformer.AddDeformingForce(point, force);
            }
        }
    }
Exemplo n.º 20
0
    private void HandleInput()
    {
        Debug.Assert(Camera.main != null, "Camera.main != null");
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                deformer.AddDeformingForce(point, force);
            }
        }
    }
Exemplo n.º 21
0
    private void HandleInput()
    {
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                // Where the ray hit the object
                Vector3 point = hit.point;
                // Move the "force" point slightly away from impact point
                point += hit.normal * forceOffset;
                deformer.AddDeformingForce(point, force);
            }
        }
    }
    void HandleInput()
    {
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        // if we hit something
        if (Physics.Raycast(inputRay, out hit))
        {
            // and that something has a MeshDeformer component, then we can deform that something!
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * forceOffset;
                deformer.AddDeformingForce(point, force);
            }
        }
    }
Exemplo n.º 23
0
    void HandleInput()
    {
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (!deformer)
            {
                return;
            }
            Debug.DrawLine(Camera.main.transform.position, hit.point, Color.blue);
            Vector3 point = hit.point;
            point -= hit.normal * forceOffset;
            deformer.AddDeformingForce(point, force);
        }
    }
Exemplo n.º 24
0
    void HandleInput()
    {
        //Cast ray to mousepos
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        //Check for collision
        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                //Apply force to mouse click position
                Vector3 point = hit.point;
                point += hit.point * forceOffset;
                deformer.AddDeformingForce(point, force);
            }
        }
    }
Exemplo n.º 25
0
    void HandleInput()
    {
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                particlesystem.transform.position = hit.point;
                particlesystem.Play();
                Vector3 point = hit.point;
                point += hit.normal * forceOffset;
                deformer.AddDeformingForce(point, force);
                //deformer.Addparticles(point);
            }
        }
    }
Exemplo n.º 26
0
    public void OnCollisionEnter(Collision collision)
    {
        PlayerState.CollisionEnter(collision);
        float force = 20f;
        ////float forceOffset = 0.1f;
        // If we hit the floor
        float dotProduct = Vector3.Dot(collision.contacts[0].normal, Vector3.up);

        if (dotProduct > 0.9f && dotProduct < 1.1f)
        {
            ParticleSystem         ps     = transform.GetChild((int)PlayerChildren.LandingParticles).GetComponent <ParticleSystem>();
            ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[ps.emission.burstCount];
            ps.emission.GetBursts(bursts);

            bursts[0].minCount = (short)Mathf.Lerp(2.0f, 6.0f, (collision.relativeVelocity.magnitude / 150.0f));
            bursts[0].maxCount = (short)Mathf.Lerp(3.0f, 8.0f, (collision.relativeVelocity.magnitude / 150.0f));
            ps.emission.SetBursts(bursts);
            ps.Play();
        }
        if (deformer)
        {
            float vibforce = collision.relativeVelocity.magnitude / 150.0f;
            //GamePad.VibrateForSeconds(playerIndex, vibforce, vibforce, 0.1f);

            float vel = collision.relativeVelocity.magnitude / collision.contacts.Length;
            for (int i = 0; i < collision.contacts.Length; i++)
            {
                Vector3 point = collision.contacts[i].point;
                deformer.AddDeformingForce(point, vel * force);
            }
        }

        if (!collision.transform.GetComponent <Player>() && !IsUnderWater)
        {
            if (Physics.Raycast(transform.position + Vector3.up * 0.5f + raycastOffsetPlayer * transform.forward, Vector3.down, raycastDist) ||
                Physics.Raycast(transform.position + Vector3.up * 0.5f - raycastOffsetPlayer * transform.forward, Vector3.down, raycastDist) ||
                Physics.Raycast(transform.position + Vector3.up * 0.5f + raycastOffsetPlayer * transform.right, Vector3.down, raycastDist) ||
                Physics.Raycast(transform.position + Vector3.up * 0.5f - raycastOffsetPlayer * transform.right, Vector3.down, raycastDist))
            {
                IsGrounded = true;
            }
        }
    }
Exemplo n.º 27
0
    void HandleInput()
    {
        //Now we have to figure out where the user is pointing. We do this by casting a ray from the camera into the scene.
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            //We use the physics engine to cast the ray and store information about what it hit. If the ray collided with something, we can retrieve the MeshDeformer component from the object that was hit.
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();

            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * forceOffset;
                deformer.AddDeformingForce(point, force);
            }
        }
    }
Exemplo n.º 28
0
    void Update()
    {
        if (handModel == null)
        {
            return;
        }
        Vector3 palmPos = handModel.GetPalmPosition();

        if (!pickedUp)
        {
            Debug.Log("Picked up !");
            RaycastHit hit;


            Vector3 fwd         = handModel.GetPalmNormal();
            Vector3 destination = tracker.position - palmPos;

            if (Physics.Raycast(palmPos, destination, out hit, Mathf.Infinity))
            {
                float distanceToGround = hit.distance;
                Debug.Log("Hitting " + hit);
                Debug.DrawRay(palmPos, destination, Color.red);

                deformer = hit.collider.GetComponent <MeshDeformer>();
                if (deformer)
                {
                    tracker.SetParent(null);


                    deformPoint  = hit.point;
                    deformPoint += hit.normal * forceOffset;
                    pickedUp     = true;
                    inTransport  = true;
                }
            }
        }

        if (inTransport)
        {
            deformer.AddDeformingForce(deformPoint, force * Vector3.Distance(tracker.transform.position, palmPos));
        }
    }
Exemplo n.º 29
0
    void HandleInput()
    {
        Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);   // Ray 的数据结构是两个 Vec3,分别是 origin, direction
        //  这里是从 camera 到 a screen point.

        RaycastHit hit;

        // hit 是储存Raycast相关信息的数据结构
        if (Physics.Raycast(inputRay, out hit)) // out 可以让函数传递出多个返回值
        {
            Debug.Log("hit");
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();  // 挂载在 与Ray碰撞的 mesh 上的 deformer
            if (deformer)
            {
                Debug.Log("call deformer");
                Vector3 point = hit.point;
                point += hit.normal * forceOffset;        // 偏移到一个很接近表面的位置
                deformer.AddDeformingForce(point, force); // 调用 Ray 接触点物体的 deformer
            }
        }
    }
Exemplo n.º 30
0
    void HandleInput()
    {
        Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>();
            if (deformer)
            {
                Vector3 point = hit.point;
                point += hit.normal * forceOffset;
                deformer.AddDeformingForce(point, force);
                Debug.Log("Force is applied ??");
            }
        }
        else
        {
            Debug.Log("Failed to find Ray collider to tooth. WTF ???????");
        }
    }