Beispiel #1
0
    public virtual void Fire()
    {
        canFire = false;

        if (Time.time < nextFireAllowed)
        {
            return;
        }

        if (Paused.GameIsPaused)
        {
            return;
        }

        if (reloader != null)
        {
            if (reloader.IsReloading)
            {
                return;
            }
            if (reloader.RoundsRemainingInClip == 0)
            {
                return;
            }

            reloader.TakeFromClip(1);
            print("Remaining : " + reloader.RoundsRemainingInClip);
        }

        nextFireAllowed = Time.time + rateOfFire;

        bool isLocalPlayerControlled = AimTarget == null;

        // useful in case additional players are added, don't have them shoot to the center of the local player's screen
        if (!isLocalPlayerControlled)
        {
            muzzle.LookAt(AimTarget.position + AimTargetOffset);
        }

        // instantiate the projectile;
        GrappleHook newHook = (GrappleHook)Instantiate(projectile, muzzle.position, muzzle.rotation);

        // shoots the projectile to the center of the screen accurately for at least 500 meters
        if (isLocalPlayerControlled)
        {
            Ray        ray = Camera.main.ViewportPointToRay(new Vector3(.5f, .5f, 0));
            RaycastHit hit;
            Vector3    targetPosition = ray.GetPoint(500);
            Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue);
            //if the raycast hits something within 500 meters then it will send the projectile there
            if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag != "Player")
            {
                targetPosition = hit.point;
            }
            newHook.transform.LookAt(targetPosition);
        }

        audioFire.Play();
        canFire = true;
    }
Beispiel #2
0
 // Update is called once per frame
 void FixedUpdate()
 {
     // rells in the player
     if (reelingIn && curHook != null && (curHook.transform.position - eyes.transform.position).sqrMagnitude >= shortDist)
     {
         GrappleHook hook = curHook.GetComponent <GrappleHook>();
         if (hook.GetSecondNode() != null)
         {
             // this code here reels the player in  make the stupid high unles you wanan break the rope
             hook.GetSecondNode().GetComponent <HingeJoint2D>().connectedAnchor *= speed;
         }
         if (hook.GetNodesCount() > 3 && (hook.GetSecondNode().transform.position - eyes.transform.position).sqrMagnitude < 0.25f)
         {
             hook.DeleteSecond();
         }
     }
     // if the player noads are not larger then the max for reeling out
     if (realout && Vector2.Distance(curHook.transform.position, transform.position) < noadMax)
     {
         GrappleHook hook = curHook.GetComponent <GrappleHook>();
         if (realout == false)
         {
             return;
         }
         hook.GetSecondNode().GetComponent <HingeJoint2D>().connectedAnchor *= speed;
         if (realout == false)
         {
             return;
         }
         hook.MakeRope1();
     }
 }
    void Start()
    {
        GrappleHook g = PlayerManager.instance.getPlayer().GetComponent <GrappleHook>();

        g.onSuccessfulGrapple += toHooked;
        g.onRelease           += toFree;
    }
Beispiel #4
0
    void UseGadget()
    {
        if (HeroEquipment.equippedGadget != null && allowGadget && Input.GetKeyDown(KeyCode.G))
        {
            switch (HeroEquipment.equippedGadget.name)
            {
            case "GrappleGun":
                Transform projectileSpawn = myEquipment.myGadget.transform.GetChild(0);

//TODO Just instantiate this in the HeroEquipment script, right along with spawning the gadget itself
                if (projectile == null)
                {
                    projectile = Instantiate(HeroEquipment.equippedAmmo, projectileSpawn.position, Quaternion.identity, projectileSpawn);
                }
                projectile.transform.localEulerAngles = Vector3.zero;
                GrappleHook hookScript = projectile.GetComponent <GrappleHook>();
                if (!hookScript.wasFired && !hookScript.retracting)
                {
                    StartCoroutine(UseGrappleGun());
                }
                break;

            default:
                break;
            }
        }
    }
    public void OnFireGrapple(InputAction.CallbackContext context)
    {
        //throw new NotImplementedException();
        var InputContext = context.phase;

        if (InputContext == InputActionPhase.Started)
        {
            if (Hook == null)
            {
                Hook = FindObjectOfType <GrappleHook>();
                GameObject GO = Instantiate(GrappleHook, ProjectilePoint.transform.position, Quaternion.identity, null).gameObject;
                GO.transform.localScale  = new Vector2(GO.transform.localScale.x * transform.localScale.x, GO.transform.localScale.y * transform.localScale.y);
                GO.transform.eulerAngles = ProjectilePoint.transform.eulerAngles;
            }
            else
            {
                Hook.SetRelease(false);
            }
            Anim.AnimPlay(PlayerAnimations.P_HoldingGrapple, true);
        }
        else if (InputContext == InputActionPhase.Performed)
        {
        }
        else if (InputContext == InputActionPhase.Canceled)
        {
            GrappleHook Hook = FindObjectOfType <GrappleHook>();
            Anim.AnimPlay(PlayerAnimations.P_HoldingGrapple, false);
            if (Hook != null)
            {
                Hook.SetRelease(true);
            }
        }
    }
Beispiel #6
0
    private void Throw()
    {
        GameObject  grappleHookInstance  = Instantiate(this.grappleHookPrefab, this.gameObject.transform.position, new Quaternion(), this.gameObject.transform);
        GrappleHook grappleHookComponent = grappleHookInstance.GetComponent <GrappleHook>();

        grappleHookComponent.LanchGrappleHook(this, this.rotateDirection);
        grappleHookComponent.OnGrappleHookFinished += this.ReturnToChaseState;
    }
Beispiel #7
0
 public override void Reload()
 {
     if (!IsLoaded)
     {
         hook = (GrappleHook)grappleHookScene.Instance();
         hookMountPoint.AddChild(hook);
         hook.GlobalTransform = hookMountPoint.GlobalTransform;
         IsLoaded             = true;
     }
 }
Beispiel #8
0
        /// <summary>
        /// Never override Awake without invoking base.Awake()
        /// </summary>
        protected override void Awake()
        {
            base.Awake();
            Ai               = GetComponent <EnemyAi>();
            m_grapple        = GameComponents.Player.GetComponent <GrappleHook>();
            gameObject.layer = LayerMask.NameToLayer("Enemy");

            if (!Targeting.Target)
            {
                Targeting.Target = GameComponents.Player.transform;
            }
        }
Beispiel #9
0
    void Awake()
    {
        //References
        rigidbody = GetComponent<Rigidbody>();
        transform = GetComponent<Transform>();
        collider = GetComponent<Collider>();
        stamina = GetComponent<Stamina>();
        grapple = GetComponent<GrappleHook>();

        //Pre-Calculations
        distToGround = collider.bounds.extents.y;

        maxSpeed = walkSpeed;
    }
Beispiel #10
0
    private void OnWeaponChange()
    {
        for (int i = 0; i < weaponCache.Length; i++)
        {
            bool isCurrent  = (i == currentWeapon - 1);
            Gun  indexedGun = weaponCache[i];
            indexedGun.gameObject.SetActive(isCurrent);

            GrappleHook hook = null;
            if (!isCurrent && (hook = indexedGun as GrappleHook) != null)
            {
                hook.Unhook(false);
            }
        }

        currentGun = weaponCache[currentWeapon - 1];
    }
 /// <summary>Used to launch the hook from the launcher.</summary>
 public override void PartAction()
 {
     if (!_launchedHook)
     {
         Debug.Log("LAUNCHER OK");
         gh             = (GameObject)Instantiate(hookPrefab, _launchPoint.position, _launchPoint.rotation);
         _hook          = gh.GetComponent <GrappleHook>();
         _launchedHook  = true;
         _hook.Launcher = this;
         _hook.Launch();
         gh = null;
     }
     else
     {
         Debug.Log("LAUNCHER N_OK");
     }
 }
Beispiel #12
0
    public override PlayerState Tick(PlayerController context)
    {
        GrappleHook grappleHook = context.GetGrappleHook();

        GrappleHook.State grappleHookState = grappleHook.GetState;
        if (grappleHookState == GrappleHook.State.NONE)
        {
            if (!hasCompleted)
            {
                // Just entered the state.
                grappleHook.Extend();
            }
            else
            {
                return(context.GetDefaultState());
            }
        }

        if (grappleHookState == GrappleHook.State.EXTENDING)
        {
            if (context.GetPlayerInput().GetDidPressGrapple())
            {
                hasCompleted = true;
                grappleHook.Retract();
            }
        }

        if (grappleHookState == GrappleHook.State.HITTING)
        {
            hasCompleted = true;
            if (context.GetPlayerInput().GetDidPressGrapple())
            {
                grappleHook.Retract();
            }

            if (context.GetPlayerInput().GetDidPressJump())
            {
                return(new StateReeling());
            }
        }

        return(this);
    }
Beispiel #13
0
    // SHOTS THE GRAPPLE HOOK
    public void StartGrapple()
    {
        if (curHook != null)
        {
            DestroyGrapple();
        }
        Vector2 destiny = grappleTarget.transform.position;

        curHook = (GameObject)Instantiate(hookPrefab, eyes.transform.position, Quaternion.identity);
        curHook.transform.LookAt(grappleTarget.transform);
        Debug.Log(curHook);
        GrappleHook hookComp = null;

        hookComp = curHook.GetComponent <GrappleHook>();
        Debug.Log(hookComp);
        hookComp.SetDestination(destiny);
        hookComp.SetTarget(grappleTarget);
        hookComp.SetMaxDistance(maxDistance);
        hookComp.player = gameObject;
        hookComp.SetEye(eyes);
    }
Beispiel #14
0
    public override PlayerState Tick(PlayerController context)
    {
        GrappleHook grappleHook = context.GetGrappleHook();

        GrappleHook.State grappleHookState = grappleHook.GetState;

        Vector2 grappleEndPos = grappleHook.GetEndingPosition();
        Vector2 curPosition   = context.transform.position;

        LagueController2D.CollisionInfo collisionInfo = context.collisionInfo;
        float directionX = Mathf.Sign(grappleEndPos.x - curPosition.x);

        float directionY = Mathf.Sign(grappleEndPos.y - curPosition.y);

        if (directionY == 1 && collisionInfo.above || directionY == -1 && collisionInfo.below)
        {
            EndGrapple(context);
            return(context.GetDefaultState());
        }

        if (directionX == 1 && collisionInfo.right || directionX == -1 && collisionInfo.left)
        {
            EndGrapple(context);
            return(new StateWallCling());
        }

        float   targetVelocity = context.GetReelSpeed();
        Vector2 direction      = (grappleEndPos - curPosition) * targetVelocity;

        // context.velocity.x = Mathf.SmoothDamp(context.velocity.x, targetVelocityX, ref context.velocityXSmoothing, context.GetVelocityXSmoothFactorGrounded());
        // context.velocity.y = context.GetGravity() * Time.deltaTime;
        context.velocity.x = direction.x;
        context.velocity.y = direction.y;

        context.FaceVelocityX();
        context.GetController().Move(context.velocity * Time.deltaTime);

        return(this);
    }
Beispiel #15
0
 void Update()
 {
     if (Input.GetKeyDown("c"))
     {
         Destroy(placeholder);
         placeholder   = Instantiate(grappleHook, playerCamera.transform.position, playerCamera.transform.rotation);
         grappleScript = placeholder.GetComponent <GrappleHook>();
         placeholder.SetActive(true);
         Debug.Log("Hook tossed!");
     }
     if (Input.GetKeyDown("v"))
     {
         Destroy(placeholder);
         Debug.Log("Hook intentionally lost!");
     }
     if (placeholder != null)
     {
         isGrappling = grappleScript.hasHit;
     }
     else
     {
         isGrappling = false;
     }
 }
Beispiel #16
0
 void Start()
 {
     grappleHook = gameObject.GetComponent <GrappleHook>();
 }
Beispiel #17
0
 void Awake()
 {
     instance    = this;
     player      = GameObject.Instantiate(playerPrefab);
     grapplehook = player.GetComponent <GrappleHook>();
 }
 private void Start()
 {
     grapple = GetComponentInChildren <GrappleHook>();
 }