Пример #1
0
        private WasteObject DropObject()
        {
            GrabbedObject.rigidbody.detectCollisions = true;
            HoldPointCollider.enabled = false;
            var obj = GrabbedObject;

            GrabbedObject = null;
            return(obj);
        }
Пример #2
0
 private void GrabObject(GameObject grabbedObject)
 {
     GrabbedObject = grabbedObject.GetComponent <WasteObject>();
     GrabbedObject.rigidbody.detectCollisions = false;
     GrabbedObject.rigidbody.velocity         = Vector3.zero;
     GrabbedObject.rigidbody.angularVelocity  = Vector3.zero;
     GrabbedObject.transform.rotation         = Quaternion.identity;
     HoldPointCollider.enabled = true;
 }
Пример #3
0
        private void Update()
        {
            if (GameManager.Paused)
            {
                return;
            }

            if (remainingSpawnDuration > 0)
            {
                remainingSpawnDuration -= Time.deltaTime;
                return;
            }

            // Movement
            var moveInput = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")).normalized;

            // Dashing
            var dashDuration = DashSpeedModifier.keys[DashSpeedModifier.length - 1].time;

            if (remainingDashDuration > -DashDelay)
            {
                remainingDashDuration -= Time.deltaTime;
            }
            if (Input.GetButtonDown("Dash") && remainingDashDuration <= -DashDelay)
            {
                remainingDashDuration = dashDuration;
            }
            var dashSpeed = remainingDashDuration <= 0 ? 1 : DashSpeedModifier.Evaluate((dashDuration - remainingDashDuration) / dashDuration);

            // Velocity
            rigidbody.velocity = moveInput * PlayerSpeed * dashSpeed + new Vector3(0, rigidbody.velocity.y, 0);
            Animator.SetBool("IsMoving", moveInput.sqrMagnitude > 0);

            if (moveInput.sqrMagnitude > 0)
            {
                // TODO: Smooth rotation
                // Use -moveInput.z to correct z-axis rotation inversion
                transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(-moveInput.z, moveInput.x) * Mathf.Rad2Deg + 90, Vector3.up);
            }

            if (WindingUp)
            {
                WindupDuration += Time.deltaTime;
            }


            // Grab/Drop
            if (grabDelay > 0)
            {
                grabDelay -= Time.deltaTime;
            }


            if (Input.GetButtonDown("Grab") && grabDelay <= 0)
            {
                if (GrabbedObject != null)
                {
                    DropObject();
                }
                else
                {
                    GrabObject();
                }
                grabDelay = GrabDelay;
            }

            // Throw/Interact
            if (Input.GetButtonDown("Throw"))
            {
                if (GrabbedObject != null)
                {
                    StartThrowWindup();
                }
                else
                {
                    Interact();
                }
            }
            if (Input.GetButtonUp("Throw") && GrabbedObject != null)
            {
                ThrowObject();
            }


            // TODO: Maybe make this better?
            if (GrabbedObject != null)
            {
                if (!GrabbedObject.gameObject.activeSelf)
                {
                    GrabbedObject = null;
                }
                else
                {
                    GrabbedObject.transform.position = HoldPoint.position;
                }
            }
            Animator.SetBool("IsHoldingObject", GrabbedObject != null);
        }