Ejemplo n.º 1
0
    void CamreaZoom()
    {
        //Aim down sights
        if (((Input.GetMouseButton(1) && gamePad.isKeyboard)) || gamePad.getButtonDown("LT"))
        {
            AdsActive = true;
            Camera TempCam = GetComponent <Camera>();
            if (isZooming == false)
            {
                adsTime = adsDuration;
            }
            isZooming = true;



            TempCam.fieldOfView = Mathf.Lerp(hipFov, adsFov, 1.0f - (adsTime / adsDuration));
        }
        else
        {
            AdsActive = false;
            if (isZooming == true)
            {
                adsTime = adsDuration;
            }
            Camera TempCam = GetComponent <Camera>();
            TempCam.fieldOfView = Mathf.Lerp(adsFov, hipFov, 1.0f - (adsTime / adsDuration));
            isZooming           = false;
        }
        adsTime -= Time.deltaTime;
    }
Ejemplo n.º 2
0
 //=====================================================================================================================================================
 void Update()
 {
     if (((Input.GetMouseButton(0) && gamePad.isKeyboard && gun.currentGun.fireType == 0) || (Input.GetMouseButtonDown(0) && gamePad.isKeyboard && gun.currentGun.fireType == 1) || (gun.currentGun.fireType == 0 && gamePad.getButtonDown("RT")) || (gun.currentGun.fireType == 1 && gamePad.getButtonPressed("RT"))) && !Shot) //right mouse click
     {
         Shot  = true;                                                                                                                                                                                                                                                                                                           //passed to gun behaviour
         laser = true;
         if (transform.gameObject.GetComponent <Cam_Raytrace>().rayHit)
         {
             pointHit = transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.point;
             GameObject objectHit = transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.collider.gameObject;
             //sparks.GetComponent<Control>().Sparks(transform.gameObject.GetComponent<Cam_Raytrace>().rayOutData.point,transform.rotation);
             Instantiate <GameObject>(emitter, pointHit, transform.rotation);
             //Debug.Log(objectHit);
             if (objectHit.transform.parent != null)
             {
                 if (objectHit.transform.parent.gameObject.GetComponent <Player_Player>())                                                       // if you're shooting a player
                 {
                     if (objectHit.transform.parent.GetComponent <Player_Player>().GetTeam() != player.GetComponent <Player_Player>().GetTeam()) // if the player is not on your team ========================================================================================================FIX IT
                     {
                         objectHit.transform.parent.GetComponent <Player_Player>().SubFromPlayerHP(gun.currentGun.damage);                       //if object hit is player, remove hp
                         objectHit.transform.parent.GetComponent <Player_Player>().SetLastHitBy(player);
                         objectHit.transform.parent.GetComponent <Player_Player>().regenDelay = 2.5f;
                         objectHit.transform.parent.GetComponent <Rigidbody>().AddForceAtPosition(camRotation.cam_forwardVec * gun.currentGun.force * 6, transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.point, ForceMode.Force);//else if object has rigid body and is not a player, knock back
                         //hit marker stuff
                         Hit = true;
                     }
                 }
             }
             if (objectHit.GetComponent <Rigidbody>())                                                                                                                                                             // if you're shooting a physics object
             {
                 objectHit.GetComponent <Rigidbody>().AddForceAtPosition(camRotation.cam_forwardVec * gun.currentGun.force, transform.gameObject.GetComponent <Cam_Raytrace>().rayOutData.point, ForceMode.Force); //else if object has rigid body and is not a player, knock back
             }
         }
     }
 }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        run = falling = walkBack = strafeR = strafeL = false;

        gamePad.getButtonPressed("ST");

        if (camRotation.isZooming)
        {
            speed       = ADSSpeed;
            strafeSpeed = ADSSpeed;
        }
        else if (sprint)
        {
            speed       = sprintSpeed;
            strafeSpeed = BaseSpeed;
        }
        else
        {
            speed       = BaseSpeed;
            strafeSpeed = BaseSpeed;
        }

        onFloor = Physics.Raycast(transform.position, -camRotation.cam_upVec, out rayOutData, 1.6f);

        //changes Drag if in air
        if (onFloor == false)
        {
            rb.drag = 1;
        }
        else
        {
            rb.drag = 5;
        }

        if (gamePad.isKeyboard == true)
        {
            if (onFloor)
            {                          //WASD movement
                if (Input.GetKey("w")) //forward
                {
                    rb.AddForce(transform.forward * Time.deltaTime * speed, ForceMode.VelocityChange);
                    run = true;
                }
                if (Input.GetKey("s"))//backward
                {
                    speed = 25;
                    rb.AddForce(-transform.forward * Time.deltaTime * speed, ForceMode.VelocityChange);
                    walkBack = true;
                }
                //-----------------------------------------------------------------
                if (Input.GetKey("d"))//right
                {
                    rb.AddForce(camRotation.cam_rightVec * Time.deltaTime * strafeSpeed, ForceMode.VelocityChange);
                    strafeR = true;
                }
                if (Input.GetKey("a"))//left
                {
                    rb.AddForce(-camRotation.cam_rightVec * Time.deltaTime * strafeSpeed, ForceMode.VelocityChange);
                    strafeL = true;
                }
            }
            else
            {
                if (Input.GetKey("w"))//forward
                {
                    rb.AddForce(transform.forward * Time.deltaTime * speed / airRestriction, ForceMode.VelocityChange);
                }
                if (Input.GetKey("s"))//backward
                {
                    rb.AddForce(-transform.forward * Time.deltaTime * speed / airRestriction, ForceMode.VelocityChange);
                }
                //-----------------------------------------------------------------
                if (Input.GetKey("d"))//right
                {
                    rb.AddForce(camRotation.cam_rightVec * Time.deltaTime * strafeSpeed / airRestriction, ForceMode.VelocityChange);
                }
                if (Input.GetKey("a"))//left
                {
                    rb.AddForce(-camRotation.cam_rightVec * Time.deltaTime * strafeSpeed / airRestriction, ForceMode.VelocityChange);
                }
                //falling = true;
            }
        }

        //analog stick movement(Xbox)
        if (gamePad.getGamePadConnected())
        {
            if (onFloor)
            {
                if (gamePad.getAxisRaw("Left", "Y") > 0.2f)
                {
                    run = true;
                }
                if (gamePad.getAxisRaw("Left", "Y") < -0.2f)
                {
                    speed    = 25;
                    walkBack = true;
                }
                if (gamePad.getAxisRaw("Left", "X") > 0.2f)
                {
                    speed   = speed / 2;
                    strafeR = true;
                }
                if (gamePad.getAxisRaw("Left", "X") < -0.2f)
                {
                    speed   = speed / 2;
                    strafeL = true;
                }
                rb.AddForce(transform.forward * Time.deltaTime * speed * gamePad.getAxisRaw("Left", "Y"), ForceMode.VelocityChange);
                rb.AddForce(camRotation.cam_rightVec * Time.deltaTime * strafeSpeed * gamePad.getAxisRaw("Left", "X"), ForceMode.VelocityChange);
            }
            else
            {
                rb.AddForce(transform.forward * Time.deltaTime * speed / airRestriction * gamePad.getAxisRaw("Left", "Y"), ForceMode.VelocityChange);
                rb.AddForce(camRotation.cam_rightVec * Time.deltaTime * strafeSpeed / airRestriction * gamePad.getAxisRaw("Left", "X"), ForceMode.VelocityChange);
                //falling = true;
            }
        }

        // jump
        if (onFloor)
        {
            if ((Input.GetKeyDown("space") && gamePad.isKeyboard) || gamePad.getButtonPressed("A"))
            {
                rb.AddForce(camRotation.cam_upVec * jumpStrength * 2, ForceMode.Force);

                jumping = true;
            }
        }

        if (!onFloor && !jumping)
        {
            falling = true;
        }
        else if (onFloor)
        {
            falling = false;
        }

        if (!gamePad.isKeyboard)
        {
            if (gamePad.getButtonDown("L3"))
            {
                sprint = true;
            }
            else if (Vector2.SqrMagnitude(new Vector2(gamePad.getAxisRaw("Left", "Y"), gamePad.getAxisRaw("Left", "X"))) < 0.2 || playerCamera.GetComponent <Combat_Shoot>().Shot)
            {
                sprint = false;
            }
        }
        else
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                sprint = true;
            }
            else if (!Input.GetKey("w") || playerCamera.GetComponent <Combat_Shoot>().Shot)
            {
                sprint = false;
            }
        }


        //rotates the player to look where camera is looking.
        transform.rotation = camRotation.transform.rotation;
        Vector3 newFwd = Vector3.Cross(camRotation.cam_upVec, camRotation.cam_rightVec);

        transform.rotation = Quaternion.LookRotation(-newFwd, transform.up);
    }