Inheritance: MonoBehaviour
コード例 #1
0
    public void RayCollide(ref collision CollState, ref Vector2 velocity, float collideDist, Rigidbody2D body)
    {
        CollState = collision.none;
        LayerMask mask = LayerMask.GetMask("ObjectLayer", "Tile");
        Vector2   main = velocity;

        main.Normalize();
        main *= collideDist; // EETU TRIGGER
        Vector2 perpendicular = new Vector2(main.y, main.x * -1);

        perpendicular /= 2f;
        Vector2 first  = (main + perpendicular);
        Vector2 second = (main + (perpendicular * -1));

        if (Physics2D.Raycast(body.position, main, collideDist, mask).collider != null)
        {
            CollState = collision.Main;
        }
        else if (Physics2D.Raycast(body.position, first, collideDist, mask).collider != null)
        {
            CollState = collision.Right;
        }
        else if (Physics2D.Raycast(body.position, second, collideDist, mask).collider != null)
        {
            CollState = collision.Left;
        }
        //print(CollState);
    }
コード例 #2
0
    void RayCollide() // gen
    {
        CollState = collision.none;
        LayerMask mask = LayerMask.GetMask("Collide");
        Vector2   main = velocity;

        main.Normalize();
        main *= collideDist; // EETU TRIGGER
        Vector2 perpendicular = new Vector2(main.y, main.x * -1);

        perpendicular /= 2f;
        Vector2 first  = (main + perpendicular);
        Vector2 second = (main + (perpendicular * -1));

        if (Physics2D.Raycast(body.position, main, collideDist, mask).collider != null)
        {
            CollState = collision.Main;
        }
        else if (Physics2D.Raycast(body.position, first, collideDist, mask).collider != null)
        {
            CollState = collision.Right;
        }
        else if (Physics2D.Raycast(body.position, second, collideDist, mask).collider != null)
        {
            CollState = collision.Left;
        }
    }
コード例 #3
0
 void OnCollision2DEnter(collision collisionInfo)
 {
     if (collisionInfo.GetComponent <Collider2D>().tag == "Bounds")
     {
         Debug.Log("we hit an obstacle");
     }
 }
コード例 #4
0
ファイル: moveCup.cs プロジェクト: jorkauf/PilloParty
 // Use this for initialization
 void Start()
 {
     PilloController.ConfigureSensorRange(0x50, 0x6f);
     grav             = this.GetComponent <Rigidbody> ();
     controller       = GameControllerObj.GetComponent <gameControler> ();
     ballScr          = ball.GetComponent <collision> ();
     grav.isKinematic = true;
 }
コード例 #5
0
    void Oncollisionenter(collision collisioninfo)    //a function with collision information (object,position etc) as parameter.
    {
        if (collisioninfo.collider.tag == 'Obstacle') //if colliding object is marked as an 'obstacle'. tags are used to mark entities of a type.

        {
            movement enabled = false; // or GetComponent<Playermovement>().enabled=false; //disable movement or force halt.
        }
    }
コード例 #6
0
    void OnCollistionEnter(collision collision)
    {
        //Get colliders from objects tagged GameController & obsticle

        GameObject obsticle = GameObject.FindWithTag("Obsticle");
        GameObject tiger    = GameObject.FindWithTag("GameController");

        Debug.Log(obsticleCollider.gameObject.name);
        Physics.IgnoreCollision(tiger.GetComponent <SphereCollider>(), collision);
        // Debug.Log("Ignored");
        Debug.Break();
    }
コード例 #7
0
ファイル: SaveData.cs プロジェクト: hiruy535/DiceRunner
    public static void SavePlayerData(collision col)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/player.hira";
        FileStream      stream    = new FileStream(path, FileMode.Create);

        PlayerData data = new PlayerData(col);


        formatter.Serialize(stream, data);
        stream.Close();
    }
コード例 #8
0
    //Keep and make refer to BP? I think? Check.

    void ContinuePlaying()
    {
        if (col0 == collision.moving)
        {
            if ((currentSlot == 0) && (lastSlot == 0))
            {
            }
            else if ((currentSlot == 1) || ((currentSlot == 0) && (lastSlot == 1)))
            {
                //If current slot is up, or the current slot is empty and the last slot is up.

                Vector2 newPos = new Vector2(this.transform.position.x, this.transform.position.y + 0.05f);
                this.transform.position = newPos;
                lastSlot = 1;                  //(up)
            }
            else if ((currentSlot == 2) || ((currentSlot == 0) && (lastSlot == 2)))
            {
                //If current slot is down, or empty and last was down

                Vector2 newPos = new Vector2(this.transform.position.x, this.transform.position.y - 0.05f);
                this.transform.position = newPos;
                lastSlot = 2;                 //(down)
            }
            else if ((currentSlot == 3) || ((currentSlot == 0) && (lastSlot == 3)))
            {
                //left

                Vector2 newPos = new Vector2(this.transform.position.x - 0.1f, this.transform.position.y);
                this.transform.position = newPos;
                lastSlot = 3;                 //(left)
            }
            else if ((currentSlot == 4) || ((currentSlot == 0) && (lastSlot == 4)))
            {
                //right
                Vector2 newPos = new Vector2(this.transform.position.x + 0.1f, this.transform.position.y);
                this.transform.position = newPos;
                lastSlot = 4;                 //(right)
            }
            else if (currentSlot == 6)
            {
                currentSlot = Slot1;
                currentPart = 1;
                Debug.Log("part 1");
                timer = 100;
                Debug.Log("Looped");
                col0 = col1;
            }
            else if (currentSlot == 5)
            {
                isPlaying = false;
            }
        }
    }
コード例 #9
0
    Vector2 CollideSteer(collision collstate, Vector2 acc, bool change = false)
    {
        float   accMag = acc.magnitude;
        Vector2 temp   = velocity;

        switch (collstate)
        {
        case collision.none:
            return(acc);

        case collision.Right:
            Vector2 perpendicularR = new Vector2(temp.y, temp.x * -1);
            perpendicularR /= 3f;
            temp            = (temp + (perpendicularR * -1));
            break;

        case collision.Left:
            Vector2 perpendicularL = new Vector2(temp.y, temp.x * -1);
            perpendicularL /= 3f;
            temp            = (temp + perpendicularL);
            break;

        case collision.Main:
            if (Mathf.Abs(velocity.x) >= Mathf.Abs(velocity.y))
            {
                Vector2 perpendicularM = new Vector2(temp.y, temp.x * -1);
                perpendicularM *= 1.5f;
                temp            = (temp + perpendicularM);
            }
            else
            {
                Vector2 perpendicularM = new Vector2(temp.y, temp.x * -1);
                perpendicularM *= -1.5f;
                temp            = (temp + perpendicularM);
            }
            break;
        }
        temp.Normalize();
        if (change)
        {
            acc = temp;
        }
        temp  *= IdleBallDistance;
        target = bodyPosition + temp;

        if (change)
        {
            acc = temp * accMag;
        }
        return(acc);
    }
コード例 #10
0
    // Start is called before the first frame update
    void Start()
    {
        _distanceJoint.enabled  = false;
        _distanceJoint2.enabled = false;
        rb   = GetComponent <Rigidbody2D>();
        coll = GetComponent <collision>();
        anim = GetComponent <Animator> ();

        GameObject levelLoad = GameObject.Find("level loader");

        load = levelLoad.GetComponent("level_loader") as level_loader;

        GameObject swapper = GameObject.Find("swap arrow");

        swapScript = swapper.GetComponent <spiderswap>();
    }
コード例 #11
0
    //Keep. Make refer to BP

    void Update()
    {
        if (isPlaying == true)
        {
            timer--;
            if (timer <= 0)
            {
                if (currentPart != 4)
                {
                    currentPart++;
                    Debug.Log("Change parts");
                    if (currentPart == 2)
                    {
                        Debug.Log("Part2");
                        currentSlot = Slot2;
                        if ((Slot1 != Slot2) && (Slot2 != 6))
                        {
                            // if slot 1 is not equal to slot 2, and slot 2 is not equal to loop. That's weird... check second part when you get back.
                            col0 = col2;
                        }
                    }
                    else if (currentPart == 3)
                    {
                        Debug.Log("Part3");
                        currentSlot = Slot3;
                        if ((Slot2 != Slot3) && (Slot2 != 6))
                        {
                            // if slot 2 is not equal to slot 3, and slot 2 is not equal to loop.
                            col0 = col3;
                        }
                    }
                    else if (currentPart == 4)
                    {
                        Debug.Log("Part4");
                        currentSlot = Slot4;
                        if ((Slot3 != Slot4) && (Slot2 != 6))
                        {
                            // if slot 3 is not equal to slot 4, and slot 2 is not equal to loop. This is probably what is causing my collision problem.
                            col0 = col4;
                        }
                    }
                    timer = 100;
                }
            }
            ContinuePlaying();
        }
    }
コード例 #12
0
 //Keep
 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag == "Player")
     {
         if (gameObject.tag == "Lift")
         {
             player.transform.parent = gameObject.transform;
         }
         else if (gameObject.tag == "Enemy")
         {
             //Boom boom or damage.
             ph.PlayerHealth--;
         }
     }
     if ((col.gameObject.tag == "Border") || (col.gameObject.tag == "Static"))
     {
         if (currentPart == 1)
         {
             Debug.Log("Hit border1");
             col0 = collision.stuck;
             Bounce();
         }
         if (currentPart == 2)
         {
             Debug.Log("Hit border2");
             col0 = collision.stuck;
             Bounce();
         }
         if (currentPart == 3)
         {
             Debug.Log("Hit border3");
             col3 = collision.stuck;
             col0 = col3;
             Bounce();
         }
         if (currentPart == 4)
         {
             Debug.Log("Hit border4");
             col4 = collision.stuck;
             col0 = col4;
             Bounce();
         }
     }
 }
コード例 #13
0
    //Move to BP. Collision stuff will get complicated, most likely.

    public void Play()
    {
        isPlaying = true;
        //Should figure out how to make play only happen after timer hits 0 again?
        Slot1 = tSlot1;
        Slot2 = tSlot2;
        Slot3 = tSlot3;
        Slot4 = tSlot4;

        currentSlot = Slot1;
        col1        = collision.moving;
        col2        = collision.moving;
        col3        = collision.moving;
        col4        = collision.moving;
        col0        = col1;



        currentPart = 1;
        timer       = 100;
    }
コード例 #14
0
 //Keep
 void OnCollisionEnter2D(Collision2D col)
 {
     Debug.Log("Hitting something");
     if (col.gameObject.tag == "Player")
     {
         //Explode or something
     }
     if (col.gameObject.tag == "Border")
     {
         if (currentPart == 1)
         {
             Debug.Log("Hit border1");
             col0 = collision.stuck;
             Bounce();
             Debug.Log("Goto bounce");
         }
         if (currentPart == 2)
         {
             Debug.Log("Hit border2");
             col0 = collision.stuck;
             Bounce();
         }
         if (currentPart == 3)
         {
             Debug.Log("Hit border3");
             col3 = collision.stuck;
             col0 = col3;
             Bounce();
         }
         if (currentPart == 4)
         {
             Debug.Log("Hit border4");
             col4 = collision.stuck;
             col0 = col4;
             Bounce();
         }
     }
 }
コード例 #15
0
    // Update is called once per frame
    void Update()
    {
        rightController.TryGetFeatureValue(UnityEngine.XR.CommonUsages.gripButton, out bool grip_right);
        rightController.TryGetFeatureValue(UnityEngine.XR.CommonUsages.triggerButton, out bool trigger_right);
        leftController.TryGetFeatureValue(UnityEngine.XR.CommonUsages.triggerButton, out bool trigger_left);

        // snow globe sphere //////////////////////////////////////
        Vector3 last_pos = snowGlobe.transform.position;

        if (!trigger_right)
        {
            snowGlobe.transform.position = new Vector3(leftController_GO.transform.position.x,
                                                       leftController_GO.transform.position.y + 0.2f, leftController_GO.transform.position.z);
        }

        Vector3 mov = last_pos - snowGlobe.transform.position;



        if (grip_right) //Selection mode
        {
            //Show the bubble and ray
            sphere_rendered.SetActive(true);
            line.enabled = true;

            // Bubble movement along z //////////////////////////////////////
            rightController.TryGetFeatureValue(CommonUsages.primary2DAxis, out Vector2 joystick_right);
            distance += joystick_right.y * 0.1f;
            if (distance < 0)
            {
                distance = 0;
            }
            else if (distance > 1000)
            {
                distance = 1000;
            }

            // Bubble scaling //////////////////////////////////////
            sphere_rendered.transform.position = transform.position + transform.TransformDirection(Vector3.forward) * distance;
            leftController.TryGetFeatureValue(CommonUsages.primary2DAxis, out Vector2 joystick_left);
            if (joystick_left.y > 0)
            {
                sphere_rendered.transform.localScale += new Vector3(0.05f, 0.05f, 0.05f);
            }
            else if (joystick_left.y < 0)
            {
                if (sphere_rendered.transform.localScale.x > 0)
                {
                    sphere_rendered.transform.localScale -= new Vector3(0.05f, 0.05f, 0.05f);
                }
            }

            //Ray drawing
            line.SetPosition(0, transform.position);
            line.SetPosition(1, transform.TransformDirection(Vector3.forward) * 1000);
            line.enabled = true;

            // Raycast selection //////////////////////////////////////
            leftController.TryGetFeatureValue(CommonUsages.primaryButton, out bool button_X);
            leftController.TryGetFeatureValue(CommonUsages.secondaryButton, out bool button_Y);

            collision col_script = (GameObject.FindGameObjectsWithTag("Sphere")[0]).GetComponent <collision>();

            List <GameObject> selection = col_script.selection;

            // Solving the on-click problem
            if (interacting)
            {
                interacting = false;
                col_script.selection.Clear();
            }

            // what happens upon copy instruction (X button)
            if (button_X)
            {
                //clean previous selection
                foreach (var item in snowglobe_objs)
                {
                    GameObject.Destroy(item);
                }
                snowglobe_objs.Clear();
                snowglobe_orig.Clear();
                selection = col_script.selection;

                //create the replics
                foreach (var item in selection)
                {
                    if (!snowglobe_objs.Contains(item))
                    {
                        float      radius = sphere_rendered.transform.localScale.x * sphere_rendered.GetComponent <SphereCollider>().radius;
                        float      scaler = 0.3f / (sphere_rendered.transform.localScale.x);
                        GameObject copy   = Instantiate(item);
                        Destroy(copy.GetComponent <Rigidbody>());
                        Destroy(copy.GetComponent <BoxCollider>());
                        MeshCollider mc = copy.AddComponent <MeshCollider>();
                        copy.transform.localScale = new Vector3(scaler, scaler, scaler);
                        float x = snowGlobe.transform.position.x + scaler * (copy.transform.position.x - sphere_rendered.transform.position.x);
                        float y = snowGlobe.transform.position.y + scaler * (copy.transform.position.y - sphere_rendered.transform.position.y);
                        float z = snowGlobe.transform.position.z + scaler * (copy.transform.position.z - sphere_rendered.transform.position.z);
                        copy.transform.position = new Vector3(x, y, z);
                        copy.transform.parent   = snowGlobe.transform;
                        snowglobe_objs.Add(copy);
                        snowglobe_orig.Add(item);
                    }
                }
            }
        }

        else
        {
            interacting = true;

            //Scaling the snowglobe
            leftController.TryGetFeatureValue(CommonUsages.primary2DAxis, out Vector2 joystick_left);
            if (joystick_left.y > 0 & snowGlobe.transform.localScale.x < 0.8f)
            {
                snowGlobe.transform.localScale += new Vector3(0.01f, 0.01f, 0.01f);
            }
            else if (joystick_left.y <0 & snowGlobe.transform.localScale.x> 0.3f)
            {
                snowGlobe.transform.localScale -= new Vector3(0.01f, 0.01f, 0.01f);
            }

            if (trigger_right & !trigger_left) // grab an object from the snow globe
            {
                //Change the color of the collider representation to be related to the current rotation axis
                switch (rotation_mode)
                {
                case 1:
                {
                    collider_visual.GetComponent <Renderer>().material.SetColor("_BaseColor", Color.red);
                    break;
                }


                case 2:
                {
                    collider_visual.GetComponent <Renderer>().material.SetColor("_BaseColor", Color.green);
                    break;
                }


                case 3:
                {
                    collider_visual.GetComponent <Renderer>().material.SetColor("_BaseColor", Color.blue);
                    break;
                }
                }

                collision_rightC col_script_right = collider_visual.GetComponent <collision_rightC>();
                if (col_script_right.selection != null)
                {
                    right_trigger_selecting = true;
                }
                for (int i = 0; i < snowglobe_objs.Count; i++)
                {
                    //make the original object suffer the same transformations as the one inside the snow globe
                    if (snowglobe_objs[i].Equals(col_script_right.selection))
                    {
                        // maintaining the same distance between object and controller
                        if (calc_distance)
                        {
                            dist          = snowglobe_objs[i].transform.position - transform.position;
                            calc_distance = false;
                        }

                        //Change original and copy positions in relation to the sphere center
                        Vector3 difference = transform.position - (snowglobe_objs[i].transform.position - dist);
                        difference /= 0.3f / (sphere_rendered.transform.localScale.x);

                        snowglobe_objs[i].transform.position = transform.position + dist;

                        // Grabbed object rotation XYZ
                        rightController.TryGetFeatureValue(CommonUsages.primary2DAxis, out Vector2 joystick_right);

                        rightController.TryGetFeatureValue(CommonUsages.primary2DAxisClick, out bool joystick_right_click);
                        if (joystick_right_click)
                        {
                            if (joystick_pressed == false)
                            {
                                rotation_mode++;
                                if (rotation_mode > 3)
                                {
                                    rotation_mode = 1;
                                }
                                joystick_pressed = true;
                            }
                        }
                        else
                        {
                            joystick_pressed = false;
                        }

                        if (rotation_mode == 2)
                        {
                            snowglobe_objs[i].transform.rotation = snowglobe_objs[i].transform.rotation * Quaternion.Euler(0, -joystick_right.y, 0);
                            snowglobe_orig[i].transform.rotation = snowglobe_orig[i].transform.rotation * Quaternion.Euler(0, -joystick_right.y, 0);
                        }
                        else if (rotation_mode == 1)
                        {
                            snowglobe_objs[i].transform.rotation = snowglobe_objs[i].transform.rotation * Quaternion.Euler(-joystick_right.y, 0, 0);
                            snowglobe_orig[i].transform.rotation = snowglobe_orig[i].transform.rotation * Quaternion.Euler(-joystick_right.y, 0, 0);
                        }
                        else
                        {
                            snowglobe_objs[i].transform.rotation = snowglobe_objs[i].transform.rotation * Quaternion.Euler(0, 0, -joystick_right.y);
                            snowglobe_orig[i].transform.rotation = snowglobe_orig[i].transform.rotation * Quaternion.Euler(0, 0, -joystick_right.y);
                        }

                        // Join translation and rotation into a singular transform
                        snowglobe_orig[i].transform.position += Quaternion.Inverse(snowGlobe.transform.rotation) * difference;
                    }
                }
            }
            else
            {
                //Rotate the snow globe

                calc_distance = true;
                rightController.TryGetFeatureValue(CommonUsages.primary2DAxis, out Vector2 joystick_right);
                snowGlobe.transform.rotation = snowGlobe.transform.rotation * Quaternion.Euler(0, -joystick_right.x, 0);
                right_trigger_selecting      = false;
            }

            sphere_rendered.SetActive(false);
            line.enabled = false;
        }
    }
コード例 #16
0
 public override void OnCollision(collision collision)
 {
     /*var m = gameObject.GetComp<MeshRenderer>().mesh;
      * m.indices.RemoveRange(0, 10);
      * m.Apply();*/
 }
コード例 #17
0
    public Vector2[] applyBehaviors(Collider2D[] GroupMobs, Collider2D[] CollisionMobs, Collider2D[] environment, Vector2 Rvelocity, Vector2 Rtarget, Vector2 position, int flags, collision collstate)
    {
        float tempSpeed = MaxSpeed;

        acceleration *= 0;
        velocity      = Rvelocity;
        target        = Rtarget;
        bodyPosition  = position;


        if ((flags & (int)behavior.separate) == (int)behavior.separate)
        {
            Vector2 sepaV = separate(CollisionMobs);
            sepaV *= sepF;
            applyForce(sepaV);
        }
        if ((flags & (int)behavior.alingment) == (int)behavior.alingment)
        {
            Vector2 ali = alingment(GroupMobs);
            ali *= aliF;
            applyForce(ali);
        }
        if ((flags & (int)behavior.cohesion) == (int)behavior.cohesion)
        {
            Vector2 coh = cohesion(GroupMobs);
            coh *= cohF;
            applyForce(coh);
        }
        if ((flags & (int)behavior.CollideEnv) == (int)behavior.CollideEnv)
        {
            Vector2 envsep = separate(environment);
            envsep *= environmentCollisionForce;
            applyForce(envsep);
        }
        if ((flags & (int)behavior.giveWanderingTargetSolo) == (int)behavior.giveWanderingTargetSolo)
        {
            GiveWanderingTarget();
        }
        if ((flags & (int)behavior.wander) == (int)behavior.wander)
        {
            Wander(false);
            Vector2 steer = seek(target);
            applyForce(steer);
        }
        if ((flags & (int)behavior.changeSoloDIr) == (int)behavior.changeSoloDIr)
        {
            Wander(true);
            Vector2 steer = seek(target);
            applyForce(steer);
        }
        if ((flags & (int)behavior.seek) == (int)behavior.seek)
        {
            Vector2 steer = seek(target);
            applyForce(steer);
        }
        if ((flags & (int)behavior.arrive) == (int)behavior.arrive)
        {
            tempSpeed = arriving(tempSpeed);
        }
        if ((flags & (int)behavior.Collide) == (int)behavior.Collide)
        {
            if ((flags & (int)behavior.wanderGroup) == (int)behavior.wanderGroup)
            {
                acceleration = CollideSteer(collstate, acceleration, true); // EETU TRIGGER
            }
            else
            {
                acceleration = CollideSteer(collstate, acceleration, true); // EETU TRIGGER
            }
        }

        velocity += acceleration;
        // limit max speed

        if (velocity.magnitude > tempSpeed)
        {
            velocity.Normalize();
            velocity *= tempSpeed;
        }

        Vector2[] powers = new Vector2[2];
        powers[0] = velocity;
        powers[1] = target;
        return(powers);
    }
コード例 #18
0
ファイル: PlayerData.cs プロジェクト: hiruy535/DiceRunner
 public PlayerData(collision col)
 {
     scores = col.scores;
 }