Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        //If they're a child of the level nodes then this is required
        transform.parent     = null;
        transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);


        //First determine the pickup type. Gravity and Smoke do not have biomes.
        MaterialPickup mp = gameObject.GetComponent <MaterialPickup>();

        if (mp.materialNo == 5 || mp.materialNo == 3)
        {
            //If a gravity or smoke material, chance of not despawning is 1/3.
            if (Random.Range(0, 3) != 0)
            {
                Destroy(gameObject);
            }
        }
        else
        {
            //Other pickups have 1/5 chance to NOT despawn
            if (Random.Range(0, 5) != 0)
            {
                Destroy(gameObject);
            }
        }
    }
Esempio n. 2
0
    private void Update()
    {
        if (!stunned)
        {
            if (rBody == null)
            {
                rBody = GetComponent <Rigidbody>();
            }

            //Get camera forward
            Vector3 flatForward = Camera.main.transform.forward;
            flatForward.y = 0;
            flatForward.Normalize();

            //Get camera right
            Vector3 flatRight = Camera.main.transform.right;
            flatRight.y = 0;
            flatRight.Normalize();

            //Start with no velocity
            Vector3 desiredVelocity = Vector3.zero;
            //Add the right/left amount
            desiredVelocity += flatRight * Input.GetAxis(horizontalAxisName);
            //Add the forward/back amount
            desiredVelocity += flatForward * -Input.GetAxis(verticalAxisName);

            if (desiredVelocity.magnitude > 0.1f)
            {
                //Normalise velocity
                desiredVelocity = desiredVelocity.normalized * speed;
                //Make sure you're using gravity
                desiredVelocity.y = rBody.velocity.y;

                //Blend to desired force
                rBody.velocity = Vector3.Lerp(rBody.velocity, desiredVelocity, Time.deltaTime * acceleration);
            }

            desiredVelocity   = rBody.velocity;
            desiredVelocity.y = 0;
            if (desiredVelocity.magnitude > 0.1f)
            {
                //Look at direction of rotation
                rBody.MoveRotation(Quaternion.Slerp(rBody.rotation, Quaternion.LookRotation(desiredVelocity, Vector3.up), Time.deltaTime * rotationSpeed));
            }

            if (Input.GetKeyDown(joystickButton0))
            {
                if (heldObj && heldObj.IsHeld())
                {
                    heldObj.Drop();
                }
                else
                {
                    Vector3 startPos = transform.position + new Vector3(0, -0.7f, 0);

                    Vector3 endPosition = transform.forward;

                    Debug.DrawRay(startPos, transform.forward, Color.blue);

                    RaycastHit hitInfo;

                    if (Physics.Raycast(startPos, transform.forward, out hitInfo, 2f))
                    {
                        heldObj = hitInfo.collider.gameObject.GetComponent <MaterialPickup>();

                        Interactable inter = hitInfo.collider.gameObject.GetComponent <Interactable>();

                        if (inter)
                        {
                            inter.Interact(gameObject);
                        }
                    }
                }
            }

            if (Input.GetKey(joystickButton1))
            {
                Vector3 startPos = transform.position + new Vector3(0, 0f, 0);

                Vector3 endPosition = transform.forward;

                Debug.DrawRay(startPos, transform.forward, Color.red);

                RaycastHit hitInfo;

                if (Physics.Raycast(startPos, transform.forward, out hitInfo, 1f))
                {
                    PlayerInput playerInput = hitInfo.collider.gameObject.GetComponent <PlayerInput>();
                    Rigidbody   rigidbody   = hitInfo.collider.gameObject.GetComponent <Rigidbody>();

                    if (rigidbody && playerInput && (playerInput.nextStunnable < Time.time))
                    {
                        rigidbody.AddForce((transform.forward * 1000 + new Vector3(0, 1000, 0)), ForceMode.Impulse);

                        playerInput.Stun();
                    }
                }
            }
        }
    }