Exemplo n.º 1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            objectToThrow = Instantiate(ObjectToThrowPrefab).GetComponent <IThrowable>();
            objectToThrow.SetActive(true);
            objectToThrow.SetStatic(true);
            objectToThrow.ResetPosition();
            objectToThrow.Position = transform.position;
        }

        if (Input.GetMouseButton(0))
        {
            var angle = Helper.GetAngle(objectToThrow.Position, CameraController.Instance.GetMousePoint());
            objectToThrow.Rotation = angle;
            transform.eulerAngles  = new Vector3(0, 0, angle);
        }

        if (Input.GetMouseButtonUp(0))
        {
            objectToThrow.SetStatic(false);
            var dir = (CameraController.Instance.GetMousePoint() - objectToThrow.Position);
            dir = Vector3.ClampMagnitude(dir, 30);
            objectToThrow.AddForce(dir * ThrowForce);
            objectToThrow.AddTorque(Random.Range(-13000, 13000));
        }
    }
Exemplo n.º 2
0
                private void Update()
                {
                    interactable = null;
                    throwable    = null;

                    Physics.Raycast(camTransform.position, camTransform.TransformDirection(Vector3.forward), out var hit, interactRange, interactableLayerMask);
                    var hitTransform = hit.transform;

                    if (hitTransform != null)
                    {
                        if (hitTransform.TryGetComponent(out interactable) && groundCheck.IsGrounded())
                        {
                            if (Input.GetKeyDown(interactionKey))
                            {
                                interactable.Interact();
                                onInteractionChanged?.Invoke();
                            }
                        }

                        if (hitTransform.TryGetComponent(out throwable))
                        {
                            if (Input.GetKeyDown(throwKey))
                            {
                                throwable.Throw();
                                onThrowableChanged?.Invoke();
                            }
                        }
                    }

                    CheckForInteractionChanges();
                }
Exemplo n.º 3
0
 public virtual void PickUp(IThrowable item)
 {
     if (HeldItem == null)
     {
         HeldItem = item.ThisGameObject();
         manager.audioManager.PlaySound("pickup", 0, 1, Random.Range(.9f, 1.1f));
     }
 }
Exemplo n.º 4
0
    // need to ensure projectile is clear
    // of player and player's orbiting objects.
    // might switch to non-physics-based implementations...
    void Throw()
    {
        if (throwables.Count > 0)
        {
            Humanoid possibleTarget = null;
            float    minAngle       = Mathf.Infinity;

            foreach (Humanoid h in humanoids)
            {
                if (!h.GetIsStaggered())
                {
                    Vector3 positionOfHumanoid = h.GetPosition();
                    Vector3 direction          = positionOfHumanoid - transform.position;
                    float   distance           = direction.magnitude;

                    if (distance < 30f)
                    {
                        float angleToHumanoid
                            = Vector3.Angle(direction, transform.forward);

                        if (angleToHumanoid
                            < minAngle)
                        {
                            minAngle       = angleToHumanoid;
                            possibleTarget = h;
                        }
                    }
                }
            }
            Vector3 shootHere = Vector3.zero;
            // if there is a target
            if (possibleTarget != null)
            {
                shootHere = possibleTarget.GetPosition();
            }
            else
            {
                Ray ray = new Ray();
                ray.origin    = Camera.main.transform.position;
                ray.direction = Camera.main.transform.forward;

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    shootHere = hit.point;
                }
            }
            // find the IThrowable that is closest to the target.
            IThrowable throwThisOne = FindClosestThrowable(shootHere);
            throwThisOne.BecomeProjectile(shootHere);
        }
    }
Exemplo n.º 5
0
                private void CheckForInteractionChanges()
                {
                    if (lastFrameInteractable != interactable)
                    {
                        onInteractionChanged?.Invoke();
                    }

                    if (lastFrameThrowable != throwable)
                    {
                        onThrowableChanged?.Invoke();
                    }

                    lastFrameInteractable = interactable;
                    lastFrameThrowable    = throwable;
                }
Exemplo n.º 6
0
    /// <summary>
    /// Interacts with IInteractable and IThrowable on the GameObject
    /// </summary>
    public void Interact(GameObject o)
    {
        IInteractable Interactable = o.GetComponent <IInteractable>();
        IThrowable    throwable    = o.gameObject.GetComponent <IThrowable>();

        if (Interactable != null)
        {
            Interactable.Interact();
        }
        else if (throwable != null)
        {
            throwableObject = throwable;
            throwableObject.Pickup();
        }
    }
Exemplo n.º 7
0
    public void Interact()
    {
        if (_currentThrowable != null)
        {
            ((MonoBehaviour)_currentThrowable).transform.parent = null;
            _currentThrowable.Throw(cameraObject.forward);
            _currentThrowable = null;
            return;
        }

        RaycastHit hit;

        if (!Physics.Raycast(cameraObject.position, cameraObject.forward, out hit, maxRayDistance, interactibleLayer))
        {
            return;
        }

        GameObject        obj = hit.collider.gameObject;
        InteractiveObject otherInteractive = obj.GetComponent <InteractiveObject>();

        if (otherInteractive == null || !otherInteractive.IsCanInteract())
        {
            return;
        }

        IThrowable throwable = otherInteractive as IThrowable;

        if (throwable != null)
        {
            var sim = obj.GetComponent <SimulatedEntityBase>();
            if (sim == null && simController.GetCurrentMode() != PlaybackMode.PlayAndRecord)
            {
                return;
            }

            throwable.Take();
            otherInteractive.transform.parent        = throwableObjectAttachTransform;
            otherInteractive.transform.localPosition = Vector3.zero;
            _currentThrowable = throwable;
            return;
        }

        otherInteractive.TryDoInteract();
    }
Exemplo n.º 8
0
    public override void PickUp(IThrowable item)
    {
        base.PickUp(item);
        PickupItem pickup = new PickupItem(item.ThisGameObject().layer);

        CurrentAction = pickup;
        if (teaching)
        {
            OnTeach();
        }
        //tutorial shit
        if (manager.Tutorial && manager.tut.Tut1PickupBerry)
        {
            manager.tut.Tut1PickupBerry = false;
            manager.tut.Tut2EatBerry    = true;
            manager.tut.DisplayNextTip(2);//eat the berry
        }
        //end tutorial shit
    }
Exemplo n.º 9
0
    private IThrowable FindClosestThrowable(Vector3 shootHere)
    {
        IThrowable throwThisOne = null;

        float minDistanceToTarget = Mathf.Infinity;

        foreach (IThrowable t in throwables)
        {
            Vector3 positionOfThrowable = t.GetPosition();
            Vector3 vectorToThrow       = shootHere - positionOfThrowable;
            float   distanceToThrow     = vectorToThrow.magnitude;
            if (minDistanceToTarget > distanceToThrow)
            {
                minDistanceToTarget = distanceToThrow;
                throwThisOne        = t;
            }
        }
        throwables.Remove(throwThisOne);
        return(throwThisOne);
    }
Exemplo n.º 10
0
    [SerializeField] Humanoid self;// = GetComponent<Humanoid>();

    // use: OnCollisionEnter to set the IThrowable to orbit.
    // Remove UpdateQueue() method / implementation.

    void Start()
    {
        allSceneObjects = FindObjectsOfType <GameObject>();
        foreach (GameObject o in allSceneObjects)
        {
            IThrowable testThrowable = o.GetComponent <IThrowable>();
            if (testThrowable != null)
            {
                possibleThrowables.Add(testThrowable);
            }

            Humanoid testHumanoid = o.GetComponent <Humanoid>();
            if (testHumanoid != null && testHumanoid != self)
            {
                humanoids.Add(testHumanoid);
                // Debug.Log(testHumanoid);
            }
        }
        StartCoroutine("UpdateThrowables");
    }
Exemplo n.º 11
0
    public void BlockedAttack(Vector3 directionOfAttack)
    {
        IThrowable throwableThatBlockedAttack = FindClosestThrowable(directionOfAttack);

        Vector3 upOrDownVec  = Vector3.zero;
        bool    ricochetLeft = Random.value >= 0.5;

        if (ricochetLeft)
        {
            upOrDownVec = Vector3.up;
        }
        else
        {
            upOrDownVec = Vector3.down;
        }
        Vector3 perpVec   = Vector3.Cross(directionOfAttack, upOrDownVec).normalized;
        Vector3 shootHere = self.GetPosition() + perpVec * 5.0f;

        throwableThatBlockedAttack.BecomeProjectile(shootHere);
    }
    void Throw()
    {
        // check to see if you have something to throw.
        if (throwables.Count > 0)
        {
            Humanoid possibleTarget = null;
            float    minAngle       = Mathf.Infinity;
            // of all the humanoids in the level
            // check to see if any are in front of you and in distance.
            // if so find the one that is closest to being directly in
            // front of you.
            foreach (Humanoid h in humanoids)
            {
                // ignore staggered enemies.
                if (!h.GetIsStaggered())
                {
                    Vector3 positionOfHumanoid = h.GetPosition();
                    Vector3 direction          = positionOfHumanoid - transform.position;
                    float   distance           = direction.magnitude;

                    if (distance < 30f)
                    {
                        float angleToHumanoid
                            = Vector3.Angle(direction, transform.forward);

                        if (angleToHumanoid
                            < minAngle)
                        {
                            minAngle       = angleToHumanoid;
                            possibleTarget = h;
                        }
                    }
                }
            }

            Vector3 shootHere = Vector3.zero;
            // if there is a target
            if (possibleTarget != null)
            {
                shootHere = possibleTarget.GetPosition();
            }
            else
            {
                Ray ray = new Ray();
                ray.origin    = Camera.main.transform.position;
                ray.direction = Camera.main.transform.forward;

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    shootHere = hit.point;
                }
            }
            // find the IThrowable that is closest to the target.
            IThrowable throwThisOne        = null;
            float      minDistanceToTarget = Mathf.Infinity;
            foreach (IThrowable t in throwables)
            {
                Vector3 positionOfThrowable = t.GetPosition();
                Vector3 vectorToThrow       = shootHere - positionOfThrowable;
                float   distanceToThrow     = vectorToThrow.magnitude;
                if (minDistanceToTarget > distanceToThrow)
                {
                    minDistanceToTarget = distanceToThrow;
                    throwThisOne        = t;
                }
            }
            throwThisOne.BecomeProjectile(shootHere);
        }
    }
Exemplo n.º 13
0
 /// <summary>
 /// Throws the stone in the direction of the camera
 /// </summary>
 public void Throw()
 {
     throwableObject.Throw(Camera.main.transform.forward);
     throwableObject = null;
 }
Exemplo n.º 14
0
    private void Awake()
    {
        objectToThrow = Instantiate(ObjectToThrowPrefab).GetComponent <IThrowable>();

        objectToThrow.SetActive(false);
    }