Exemple #1
0
 void GrabObject()
 {
     if (damObject != null && damObject.canBeGrabbed() && objectHolded == false)
     {
         moveSpeed /= speedMalus;
         damObject.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
         damObject.transform.parent = this.gameObject.transform;
         action       = CharacterAction.BringingObject;
         objectHolded = true;
         damObject.grabObject(transform, team, playerId);
     }
 }
Exemple #2
0
    void ThrowRPC(int ItemID)
    {
        Throwable Item = PhotonView.Find(ItemID).GetComponent <Throwable>();

        Item.GetComponent <Rigidbody>().AddForce(camera.transform.forward * 1000);
        Item.transform.parent = GameObject.Find("/Environment/Interactables/Rocks").transform;
    }
    void Grab(Throwable obj)
    {
        holdPoint.rotation = Quaternion.identity;
        PowerBlock pb = obj.GetComponent <PowerBlock>();

        if (pb != null && pb.isPowered)
        {
            pb.DisconnectPower();
            return;
        }
        // calculate velocity
        Vector2 collisionVel = (obj.rb.mass * obj.rb.velocity + rb.mass * rb.velocity) / (obj.rb.mass + rb.mass);

        rb.velocity = collisionVel;
        foreach (Collider2D childCollider in obj.gameObject.GetComponentsInChildren <Collider2D>())
        {
            childCollider.enabled = false;
        }

        heldObject = obj;
        Collider2D c = heldObject.GetComponent <Collider2D>();

        c.enabled = false;
        heldObject.rb.isKinematic     = true;
        heldObject.rb.angularVelocity = 0f;

        heldObject.transform.parent = holdPoint;
        heldObject.rb.velocity      = Vector3.zero;

        heldObject.transform.localPosition = Vector3.zero;
        heldObject.transform.localRotation = Quaternion.identity;
    }
Exemple #4
0
    // carriedItem must not be null to call this
    private void SetupCarryRange()
    {
        float carriedRadius = circleCollider.radius;
        float roomForJesus  = 0.2f;

        if (carriedItem is Box)
        {
            float boxRadius = carriedItem.GetComponent <BoxCollider2D> ().bounds.extents.magnitude;
            carriedRadius = boxRadius + roomForJesus;
        }
        else                    // its a robot
        {
            float robotRadius = carriedItem.GetComponent <CircleCollider2D> ().radius;
            carriedRadius = robotRadius + roomForJesus;
        }
        carryItemDistance = circleCollider.radius + carriedRadius;
    }
Exemple #5
0
    void ThrowRPC(int itemID)
    {
        Throwable item = PhotonView.Find(itemID).GetComponent <Throwable>();

        // sets the Inverse Kinematics to false so the player's hand can be reset to normal
        GetComponent <IkBehaviour>().ikActive = false;

        // Gesture aim
        item.GetComponent <Rigidbody>().AddForce((actualCamera.transform.forward + (actualCamera.transform.rotation * crosshair.GETCrosshairOffsetFromCentre()) * 0.002f).normalized * 1000);
        item.transform.parent = GameObject.Find("/Environment/Interactables/Rocks").transform;
    }
Exemple #6
0
    private Throwable ThrowObject(Throwable throwable, Vector3 throwForce)
    {
        Throwable   aux = Instantiate(throwable, orbSpawn.transform.position, Quaternion.identity);
        Rigidbody2D rb  = aux.GetComponent <Rigidbody2D>();

        if (rb != null)
        {
            rb.AddForce(throwForce, ForceMode2D.Impulse);
        }
        return(aux);
    }
Exemple #7
0
    // Called by the Event System when we click on an object, receives a game object to hold.
    // The object given must have a throwable object, otherwise we don't do anything
    public void HoldGameObject(GameObject throwableObject)
    {
        Throwable throwable = throwableObject.GetComponent <Throwable>();

        if (throwable != null)
        {
            _grabbedThrowable = throwable;
            throwableObject.transform.parent = this.gameObject.transform;    // Set object as a child so it'll follow our controller
            _grabbedThrowable.GetComponent <Rigidbody>().isKinematic = true; // Stops physics from affecting the grabbed object
            _currentGrabbedLocation = _grabbedThrowable.transform.position;  // Tack the location of our object so we can throw it later
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (goal == null)
        {
            goal = GameObject.Find("PlaceDiskHere").GetComponent <Transform>();
        }

        if (_hand.controller != null)
        {
            if (_hand.GetStandardInteractionButtonDown())
            {
                HandleTriggerClicked();
            }

            if (_hand.controller.GetPressDown(touchpad))
            {
                GameManager.instance._levelManager.SwitchEnvironment();
            }

            if (_hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip))
            {
                disc.GetComponent <Disc>().Teleport();
            }
        }


        if ((Vector3.Distance(disc.transform.position, goal.position) < 1) || Input.GetKeyDown(KeyCode.R))
        {
            inGoal = true;
        }
        else
        {
            inGoal = false;
        }

        if (inGoal == true)
        {
            PlaceInGoal();
        }
    }
Exemple #9
0
 // Called by the Event System when we release our click on a game object.
 // Release our held object and throw it based off our controller motino
 public void ReleaseGameObject()
 {
     // Only throw an object if we're holding onto something
     if (_grabbedThrowable != null)
     {
         _grabbedThrowable.transform.parent = null;                                            // Un-parent throwable object so it doesn't follow the controller
         Rigidbody rigidBody = _grabbedThrowable.GetComponent <Rigidbody>();
         rigidBody.isKinematic = false;                                                        // Re-enables the physics engine.
         Vector3 throwVector = _grabbedThrowable.transform.position - _currentGrabbedLocation; // Get the direction that we're throwing
         rigidBody.AddForce(throwVector * 10, ForceMode.Impulse);                              // Throws the ball by sending a force
         _grabbedThrowable = null;
     }
 }
    void Throw()
    {
        heldObject.rb.isKinematic   = false;
        heldObject.rb.velocity      = rb.velocity;
        heldObject.transform.parent = null;
        heldObject.GetComponent <Collider2D>().enabled = true;
        foreach (Collider2D c in heldObject.GetComponentsInChildren <Collider2D>())
        {
            c.enabled = true;
        }

        heldObject.rb.AddForce(aimDir.normalized * maxForce * dragMult, ForceMode2D.Impulse);
        rb.AddForce(-1 * aimDir.normalized * maxForce * dragMult, ForceMode2D.Impulse);
//        holdPoint.rotation = Quaternion.identity;

        heldObject = null;
    }