Example #1
0
    // Update is called once per frame
    void Update()
    {
        //Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
        //difference.Normalize();

        //float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;

        rotZ         = Mathf.Atan2(joyStick.Vertical(), joyStick.Horizontal()) * Mathf.Rad2Deg;
        Arm.rotation = Quaternion.Euler(0f, 0f, rotZ);
        fPos         = fPoint.position;
        fx           = fPoint.position.x;
        fy           = fPoint.position.y;


        {
            if ((Math.Abs(joyStick.Vertical()) > 0.6 || Math.Abs(joyStick.Horizontal()) > 0.6) && Time.time > TimeToFire && joyStick.isTouched)
            {
                TimeToFire = Time.time + 1 / FireRate;
                // Debug.Log("X");
                // Debug.Log(isLocalPlayer);
                CmdFiring();
                CmdFire(fPos, new Vector2(joyStick.Horizontal(), (joyStick.Vertical())));

                //GameObject bullet = (GameObject)Instantiate(BulletTrailPrefa, fPos, Quaternion.Euler(0f, 0f, rotZ));
                //bullet.GetComponent<Rigidbody2D>().AddRelativeForce(new Vector2(4000, 0));
                //isFiring = false;
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        //Shoot();



        /*      if (FireRate == 0)
         *    {
         *        //if (Input.GetButtonDown("Fire1"))
         *        if(Math.Abs(JoyStick.Vertical())>0.6 || Math.Abs(JoyStick.Horizontal())>0.6)
         *        {
         *            CmdFire();
         *        }
         *    }
         *    else {*/
        // if (isLocalPlayer)
        {
            if ((Math.Abs(JoyStick.Vertical()) > 0.6 || Math.Abs(JoyStick.Horizontal()) > 0.6) && Time.time > TimeToFire)
            {
                TimeToFire = Time.time + 1 / FireRate;
                //Debug.Log("X");
                //this.GetComponent<NetworkIdentity>().AssignClientAuthority(this.GetComponent<NetworkIdentity>().connectionToClient);
                //Debug.Log(isLocalPlayer);

                CmdFire();
            }
        }
    }
Example #3
0
    public void ShootGuns()
    {
        if (plasmaShotCooldownRemaining <= 0)
        {
            if (fireLeftCannonNext)
            {
                GameObject newProjectile = Instantiate(plasmaShot, leftCannonEmitPos.position, transform.rotation) as GameObject; //Saves the projectile after instantiation
                Vector2    myVelocity    = gameObject.GetComponent <Rigidbody2D> ().velocity;                                     //Gets our current velocity
                newProjectile.GetComponent <Rigidbody2D> ().velocity = new Vector2(((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.x) / 3, ((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.y) / 3);

                GameObject barrelEffect = Instantiate(plasmaShotBarrelFlashEffect, leftCannonEmitPos.position, transform.rotation) as GameObject;
                barrelEffect.transform.SetParent(gameObject.transform);
            }
            else
            {
                GameObject newProjectile = Instantiate(plasmaShot, rightCannonEmitPos.position, transform.rotation) as GameObject; //Saves the projectile after instantiation
                Vector2    myVelocity    = gameObject.GetComponent <Rigidbody2D> ().velocity;                                      //Gets our current velocity
                newProjectile.GetComponent <Rigidbody2D> ().velocity = new Vector2(((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.x) / 3, ((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.y) / 3);

                GameObject barrelEffect = Instantiate(plasmaShotBarrelFlashEffect, rightCannonEmitPos.position, transform.rotation) as GameObject;
                barrelEffect.transform.SetParent(gameObject.transform);
            }

            fireLeftCannonNext          = !fireLeftCannonNext;
            plasmaShotCooldownRemaining = plasmaShotCooldown;            //Reset the cooldown
        }

        //Only fires rockests if the ship is pointing in the target direction, and the user has move the analog more than 20% in any direction
        if (rocketCooldownRemaining <= 0 && Vector2.Angle(transform.up, new Vector2(directionShootingJoystick.Horizontal(), directionShootingJoystick.Vertical())) < 10 && new Vector2(directionShootingJoystick.Horizontal(), directionShootingJoystick.Vertical()).magnitude > 0.2f)
        {
            GameObject newProjectile = Instantiate(rocket, leftRocketEmitPos.position, transform.rotation) as GameObject; //Saves the projectile after instantiation
            Vector2    myVelocity    = gameObject.GetComponent <Rigidbody2D> ().velocity;                                 //Gets our current velocity
            newProjectile.GetComponent <Rigidbody2D> ().velocity = new Vector2(((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.x) / 3, ((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.y) / 3);

            newProjectile = Instantiate(rocket, rightRocketEmitPos.position, transform.rotation) as GameObject;             //Saves the projectile after instantiation
            newProjectile.GetComponent <Rigidbody2D> ().velocity = new Vector2(((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.x) / 3, ((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.y) / 3);

            rocketCooldownRemaining = rocketCooldown;                     //Reset the cooldown
        }
        else if (rocketCooldownRemaining <= 0 && Input.GetMouseButton(0)) //Mouse control

        {
            Vector3 mouseWorldPos    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 mouseRelativePos = new Vector2(mouseWorldPos.x - transform.position.x, mouseWorldPos.y - transform.position.y);
            if (Vector2.Angle(transform.up, new Vector2(mouseRelativePos.x, mouseRelativePos.y)) < 10f)
            {
                GameObject newProjectile = Instantiate(rocket, leftRocketEmitPos.position, transform.rotation) as GameObject; //Saves the projectile after instantiation
                Vector2    myVelocity    = gameObject.GetComponent <Rigidbody2D> ().velocity;                                 //Gets our current velocity
                newProjectile.GetComponent <Rigidbody2D> ().velocity = new Vector2(((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.x) / 3, ((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.y) / 3);

                newProjectile = Instantiate(rocket, rightRocketEmitPos.position, transform.rotation) as GameObject;                 //Saves the projectile after instantiation
                newProjectile.GetComponent <Rigidbody2D> ().velocity = new Vector2(((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.x) / 3, ((myVelocity.y * transform.up.y + myVelocity.x * transform.up.x) * newProjectile.transform.up.y) / 3);

                rocketCooldownRemaining = rocketCooldown;                //Reset the cooldown
            }
        }
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        //Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
        //difference.Normalize();

        //float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;

        rotZ         = Mathf.Atan2(joyStick.Vertical(), joyStick.Horizontal()) * Mathf.Rad2Deg;
        Arm.rotation = Quaternion.Euler(0f, 0f, rotZ);
    }
Example #5
0
    void FixedUpdate()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical   = Input.GetAxis("Vertical");

        ArmRotationInZ = Mathf.Atan2(joyStickRight.Vertical(), joyStickRight.Horizontal()) * Mathf.Rad2Deg;
        Arm.rotation   = Quaternion.Euler(0, 0, ArmRotationInZ);

        PlayerFacing(ArmRotationInZ);

        GetComponent <Rigidbody2D>().velocity = new Vector2(joyStickLeft.Horizontal() * speed, GetComponent <Rigidbody2D>().velocity.y);

        GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, joyStickLeft.Vertical() * Flyspeed));

        Debug.Log("Fly speed" + joyStickLeft.Vertical() * Flyspeed);
    }
Example #6
0
 // Update is called once per frame
 void Update()
 {
     fPos = fPoint.position;
     rotZ = Mathf.Atan2(joyStick.Vertical(), joyStick.Horizontal()) * Mathf.Rad2Deg;
     if (Time.time - TimeToThrow < 0)
     {
         GrenadesLeftText.text = (TimeToThrow - Time.time).ToString("f0");
     }
     else
     {
         GrenadeImg.GetComponent <Image>().color = new Color32(255, 255, 255, 255);
     }
 }
Example #7
0
    private Vector3 dirInput()
    {
        Vector3 dir = Vector3.zero;

                #if UNITY_STANDALONE || UNITY_WEBPLAYER
        dir.x = Input.GetAxis("Horizontal");
        dir.z = Input.GetAxis("Vertical");

        return(dir);
                #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
        dir.x = joystick.Horizontal();
        dir.z = joystick.Vertical();
                #endif

        if (dir.magnitude > 1)
        {
            dir.Normalize();
        }

        return(dir);
    }
Example #8
0
    void Update()
    {
        //float deltaX = Input.GetAxis("Horizontal") * speedPlayer;
        //float deltaZ = Input.GetAxis("Vertical") * speedPlayer;

        deltaX = _JoyStick.Horizontal() * speedPlayer;
        deltaZ = _JoyStick.Vertical() * speedPlayer;
        Vector3 movePlayer = new Vector3(deltaX, gravityPlayer, deltaZ);

        movePlayer  = Vector3.ClampMagnitude(movePlayer, speedPlayer);
        movePlayer *= Time.deltaTime;

        movePlayer = transform.TransformDirection(movePlayer);
        _charController.Move(movePlayer);


        //if (_charController.isGrounded && Input.GetButton("Jump"))
        //{
        //    movePlayer.y = jumpGravity;
        //    movePlayer.y -= gravityPlayer * Time.deltaTime;
        //    _charController.Move(movePlayer * Time.deltaTime);
        //}
    }
Example #9
0
 void Move()
 {
     transform.Translate(Vector3.right * JoyStick.Horizontal() * speed * Time.deltaTime);//referenced two methods using Joystick as a handle to the script
     transform.Translate(Vector3.forward * JoyStick.Vertical() * speed * Time.deltaTime);
 }
Example #10
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.J))
        {
            attack_A();
        }

        if (Input.GetKeyDown(KeyCode.K))
        {
            attack_B();
        }

        if (Input.GetKey(KeyCode.M))
        {
            if (!guardBreak)
            {
                isGuard = true;
            }
        }

        if (Input.GetKeyUp(KeyCode.M))
        {
            isGuard = false;
        }

        if (Input.GetKeyDown(KeyCode.Comma))
        {
            Dodge();
        }

        if (isDead)
        {
            playerState = PlayerState.dead;
            animator.SetTrigger("dead");
            //Invoke ("gameOver", 4);
        }
        else if (isDown)
        {
        }
        else if (isHit)
        {
            animator.SetTrigger("isFall");
            Camera.main.GetComponent <Rotate_CamCtrl>().fix = true;
            Invoke("gameOver", 1);
        }
        else if (!isAir && isGuard)
        {
            if (!isDelay && !moveDelay && !invincibility)
            {
                animator.SetBool("isGuard", true);
                guardTimer = 5f;
                // 가드 게이지가 다시 풀로 차기까지 5초
            }
        }
        else
        {
            animator.SetBool("isGuard", false);

            if (guardTimer > 0)
            {
                guardTimer -= Time.deltaTime;
            }
            else
            {
                guardHp    = 10;
                guardBreak = false;
                GuardMgr.GetComponent <GuardBtnMgr>().setGuardBreak(false);
                GuardMgr.GetComponent <GuardBtnMgr>().setGuardGuage(1f);
            }

            Vector3   moveDir         = Vector3.zero;
            Transform CameraTransform = Camera.main.transform;
            Vector3   forwardVector3  = CameraTransform.forward;
            forwardVector3.y = 0;
            forwardVector3.Normalize();
            Vector3 rightVector3 = new Vector3(forwardVector3.z, 0, -forwardVector3.x);

            if (isMobile)
            {
                //moveDir.x = joystick.Horizontal();
                //moveDir.z = joystick.Vertical();
                moveDir = forwardVector3 * joystick.Vertical() + rightVector3 * joystick.Horizontal();
            }
            else
            {
                h = Input.GetAxis("Horizontal");
                v = Input.GetAxis("Vertical");
                //moveDir = (Vector3.forward * v) + (Vector3.right * h);
                moveDir = (forwardVector3 * v) + (rightVector3 * h);
            }

            v = moveDir.z;
            h = moveDir.x;

            if (v >= 0.1f || v <= -0.1f || h >= 0.1f || h <= -0.1f)
            {
                playerState = PlayerState.run;
                animator.SetBool("isRun", true);
                moveSpeed = 2.5f;
            }
            else
            {
                playerState = PlayerState.idle;
                animator.SetBool("isRun", false);
                moveSpeed = 0f;
            }

            if (isCombo)
            {
                animator.SetBool("isDelay", true);
                animator.SetBool("isRun", false);
                moveSpeed = 0f;

                playerState = PlayerState.attack;

                comboTimer -= Time.deltaTime;
            }

            if (comboTimer <= 0)
            {
                animator.SetBool("isDelay", false);
                isCombo    = false;
                isDelay    = false;
                rotDelay   = false;
                comboTimer = 0;
                comboIndex = 0;
                motionEnd(0);
            }

            if (!rotDelay && !isAir && moveDir != Vector3.zero)
            {
                tr.rotation = Quaternion.LookRotation(moveDir);
            }

            if (moveDelay)
            {
                moveDelayTimer -= Time.deltaTime;
                if (moveDelayTimer <= 0)
                {
                    animator.SetBool("isDelay", false);
                    moveDelay = false;
                    rotDelay  = false;
                }
            }
            else if (!isAir)
            {
                //animator.SetBool("isDelay", false);
                tr.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
                camPos.transform.position = new Vector3(tr.position.x - 0.01f, tr.position.y + 1.87f, tr.position.z - 2.64f);
            }

            this.GetComponent <Rigidbody>().isKinematic = false;

            if (playerHp / initHp < 0.2f)
            {
                imgHpbar.color = Color.red;
            }
            else if (playerHp / initHp < 0.5f)
            {
                imgHpbar.color = Color.yellow;
            }
            else
            {
                imgHpbar.color = Color.green;
            }
            imgHpbar.fillAmount = playerHp / initHp;
        }
    }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        /*//mobile input stuff
         * float smooth = 1, sensV = 1, sensH = 1;
         * CurAc = Vector3.Lerp(curAc, Input.acceleration-zeroAc, Time.deltaTime/smooth);
         * GetAxisV = Mathf.Clamp(curAc.y * sensV, -1, 1);
         * GetAxisH = Mathf.Clamp(curAc.x * sensH, -1, 1);*/

        float previousAngle = transform.rotation.eulerAngles.z;

        myVelocity = gameObject.GetComponent <Rigidbody2D>().velocity;       //Gets our current velocity, used for sound, and speed checks
        float currentSpeed = myVelocity.magnitude;

        //Analog Rotating stuff
        if (directionShootingJoystick.Vertical() < 0)           //Checks if the shoot analog/keys has negative vertial direction. If so, a negative rotation is applied (ask Ben if needed).
        {
            transform.rotation = Quaternion.RotateTowards(
                transform.rotation, Quaternion.AngleAxis(
                    -Vector2.Angle(Vector2.right, new Vector2(directionShootingJoystick.Horizontal(), directionShootingJoystick.Vertical())) - 90f,
                    Vector3.forward),
                rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude), 0.3f, 1f))*/);
        }
        else if (directionShootingJoystick.Vertical() != 0 || directionShootingJoystick.Horizontal() != 0)             //Checks if the shoot analog/keys is in use in any other direction
        {
            transform.rotation = Quaternion.RotateTowards(
                transform.rotation, Quaternion.AngleAxis(
                    Vector2.Angle(Vector2.right, new Vector2(directionShootingJoystick.Horizontal(), directionShootingJoystick.Vertical())) - 90f,
                    Vector3.forward),
                rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude), 0.3f, 1f))*/);
        }
        else if (movementJoystick.Vertical() < 0)              //Checks if the move analog/keys has negative vertial direction. If so, a negative rotation is applied (ask Ben if needed).
        {
            transform.rotation = Quaternion.RotateTowards(
                transform.rotation, Quaternion.AngleAxis(
                    -Vector2.Angle(Vector2.right, new Vector2(movementJoystick.Horizontal(), movementJoystick.Vertical())) - 90f,
                    Vector3.forward),
                rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude), 0.3f, 1f))*/);
        }
        else if (movementJoystick.Vertical() != 0 || movementJoystick.Horizontal() != 0)              //Checks if the move analog/keys is in use in any other direction
        {
            transform.rotation = Quaternion.RotateTowards(
                transform.rotation, Quaternion.AngleAxis(
                    Vector2.Angle(Vector2.right, new Vector2(movementJoystick.Horizontal(), movementJoystick.Vertical())) - 90f,
                    Vector3.forward),
                rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude), 0.3f, 1f))*/);
        }

        //Should ship also start shooting?
        if (directionShootingJoystick.Vertical() != 0 || directionShootingJoystick.Horizontal() != 0)
        {
            gameObject.GetComponent <Shoot> ().startShooting();
        }

        /*//This is purely a control for PC/Mac. It checks keyboard input at the same time so it only works to shoot as you move, but doesn't work on mobile touch screens
         * else if (Input.GetMouseButton (0) && (Input.GetKey (KeyCode.W) || Input.GetKey (KeyCode.A) || Input.GetKey (KeyCode.S) || Input.GetKey (KeyCode.D))) {//Mouse control for pc/mac where mouse is used to aim and shoot
         *
         *      gameObject.GetComponent<Shoot> ().startShooting ();
         *
         *      Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
         *      Vector2 mouseRelativePos = new Vector2 (mouseWorldPos.x - transform.position.x, mouseWorldPos.y - transform.position.y);
         *
         *      if (mouseRelativePos.y > 0) {
         *              transform.rotation = Quaternion.RotateTowards (
         *                      transform.rotation, Quaternion.AngleAxis (
         *                      Vector2.Angle (Vector2.right, new Vector2 (mouseRelativePos.x, mouseRelativePos.y)) - 90f,
         *                      Vector3.forward),
         *                      rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude), 0.3f, 1f))*//*);
         *      } else {
         *              transform.rotation = Quaternion.RotateTowards (
         *                      transform.rotation, Quaternion.AngleAxis (
         *                      -Vector2.Angle (Vector2.right, new Vector2 (mouseRelativePos.x, mouseRelativePos.y)) - 90f,
         *                      Vector3.forward),
         *                      rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude), 0.3f, 1f))*//*);
         *      }
         * }*/else
        {
            gameObject.GetComponent <Shoot> ().stopShooting();            //As the shoot analog wasn't in use, don't shoot
        }



        //Zero all the thrusters
        theParticleSystem                       = rightThruster.GetComponent <ParticleSystem> ().emission;
        theParticleSystemsRateCurve             = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax = 0;
        theParticleSystem.rate                  = theParticleSystemsRateCurve;

        theParticleSystem                       = leftThruster.GetComponent <ParticleSystem> ().emission;
        theParticleSystemsRateCurve             = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax = 0;
        theParticleSystem.rate                  = theParticleSystemsRateCurve;

        //Increase particles to front thrusts
        theParticleSystem                       = rightFrontThrust.GetComponent <ParticleSystem>().emission;
        theParticleSystemsRateCurve             = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax = 0;
        theParticleSystem.rate                  = theParticleSystemsRateCurve;

        theParticleSystem                       = leftFrontThrust.GetComponent <ParticleSystem>().emission;
        theParticleSystemsRateCurve             = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax = 0;
        theParticleSystem.rate                  = theParticleSystemsRateCurve;
        //All thrusters are now zeroed

        float newAngle = transform.rotation.eulerAngles.z;

        float rotationAmount = newAngle - previousAngle;

        if (rotationAmount > 0)
        {
            //Increase particles to rear thrusts
            theParticleSystem                       = rightThruster.GetComponent <ParticleSystem> ().emission;
            theParticleSystemsRateCurve             = theParticleSystem.rate;
            theParticleSystemsRateCurve.constantMax = 100;
            theParticleSystem.rate                  = theParticleSystemsRateCurve;

            theParticleSystem                       = leftFrontThrust.GetComponent <ParticleSystem>().emission;
            theParticleSystemsRateCurve             = theParticleSystem.rate;
            theParticleSystemsRateCurve.constantMax = 100;
            theParticleSystem.rate                  = theParticleSystemsRateCurve;
        }
        else if (rotationAmount < 0)
        {
            theParticleSystem                       = leftThruster.GetComponent <ParticleSystem> ().emission;
            theParticleSystemsRateCurve             = theParticleSystem.rate;
            theParticleSystemsRateCurve.constantMax = 100;
            theParticleSystem.rate                  = theParticleSystemsRateCurve;

            //Increase particles to front thrusts
            theParticleSystem                       = rightFrontThrust.GetComponent <ParticleSystem>().emission;
            theParticleSystemsRateCurve             = theParticleSystem.rate;
            theParticleSystemsRateCurve.constantMax = 100;
            theParticleSystem.rate                  = theParticleSystemsRateCurve;
        }


        //Movement and sound
        Vector2 moveAngleInput = new Vector2(movementJoystick.Horizontal(), movementJoystick.Vertical());
        //Vector2 myVelocity = gameObject.GetComponent<Rigidbody2D>().velocity;//Gets our current velocity, used for sound, and speed checks


        float thrustMagnitude = moveAngleInput.magnitude;        //This is just for sound

        //float percentOfThrustFromRear = (180 - Mathf.Abs(Vector2.Angle (Vector2.right, new Vector2 (transform.up.x,transform.up.y)) - Vector2.Angle (Vector2.right, new Vector2 (movementJoystick.Horizontal (), movementJoystick.Vertical ())))) / 180;
        thrusterSound.pitch  = thrusterIdlePitch + myVelocity.magnitude / 30 + (thrustMagnitude / 3);        //Increase pitch a bit more for faster sound
        thrusterSound.volume = thrusterIdleVolume + myVelocity.magnitude / 100 + (thrustMagnitude / 3);

        //This works good as well
        //velocityToAdd += moveAngleInput * (((180 - angleDifference) / 360) + 0.5f);



        //angle of analog from nose
        angleDifference = (Vector2.Angle(moveAngleInput, new Vector2(transform.up.x, transform.up.y)));

        if (angleDifference < 90)
        {
            //Increases speed limit when going forward
            speedLimitToUse = Mathf.Clamp(strafeAndReverseSpeedLimit + ((forwardSpeedLimit - strafeAndReverseSpeedLimit) * (1 - angleDifference / 90)), currentSpeed, forwardSpeedLimit);

            //Add velocity for forward movement, using accerlation curve
            velocityToAdd += (moveAngleInput * (1 - angleDifference / 90) * forwardAccel * Time.deltaTime) * (1.5f - Mathf.Clamp((currentSpeed / forwardSpeedLimit - 4), 0.5f, 1f));
        }
        else
        {
            speedLimitToUse = Mathf.Clamp(strafeAndReverseSpeedLimit, currentSpeed, forwardSpeedLimit);
        }

        speedLimitToUse *= (1 - percentageFrostSlow);

        //Debug.Log (currentSpeed);

        //Inrcase velocity in move direction accordingly

        //Limit magnitude based on newly calculated top speed


        /*
         * //Try to apply some amount forward velocity
         * angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (transform.up.x, transform.up.y)));
         * if (angleDifference < 90) {
         *
         *      //velocity to add is here
         *      velocityToCheck = moveAngleInput * (1 - angleDifference / 90) * forwardAccel * Time.deltaTime;
         *      velocityToCheck *= 1.5f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude - 4), 0.5f, 1f);//Better working one
         *
         *      //float currentSpeed = myVelocity.y * -transform.up.y + myVelocity.x * -transform.up.x;
         *      float newSpeed = (myVelocity.y + velocityToCheck.y) * transform.up.y + (myVelocity.x + velocityToCheck.x) * transform.up.x;
         *
         *      //Don't add it if it puts you over the speed limit
         *      if (newSpeed < forwardSpeedLimit * (1 - angleDifference / 90)) {
         *              velocityToAdd += velocityToCheck;
         *      }
         * }
         */

        //Increase particles to rear thrusts
        theParticleSystem                        = rightThruster.GetComponent <ParticleSystem>().emission;
        theParticleSystemsRateCurve              = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 300);
        theParticleSystem.rate                   = theParticleSystemsRateCurve;

        theParticleSystem                        = leftThruster.GetComponent <ParticleSystem>().emission;
        theParticleSystemsRateCurve              = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 300);
        theParticleSystem.rate                   = theParticleSystemsRateCurve;

        /*
         * //Try to apply some amount of backward velocity
         * angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (-transform.up.x, -transform.up.y)));
         * if (angleDifference < 90) {
         *
         *      velocityToCheck = /*-transform.up*//* moveAngleInput * (1 - angleDifference / 90) * backwardAccel * Time.deltaTime;
         *
         *      //float currentSpeed = myVelocity.y * -transform.up.y + myVelocity.x * -transform.up.x;
         *      float newSpeed = (myVelocity.y + velocityToCheck.y) * -transform.up.y + (myVelocity.x + velocityToCheck.x) * -transform.up.x;
         *
         *      //Don't add it if it puts you over the speed limit
         *      if (newSpeed < backwardSpeedLimit * (1 - angleDifference / 90)) {
         *              velocityToAdd += velocityToCheck;
         *      }
         * }*/

        angleDifference = (Vector2.Angle(moveAngleInput, new Vector2(-transform.up.x, -transform.up.y)));
        if (angleDifference < 90)
        {
            velocityToAdd += moveAngleInput * (1 - angleDifference / 90) * backwardAccel * Time.deltaTime;
        }

        //Increase particles to front thrusts
        theParticleSystem                        = rightFrontThrust.GetComponent <ParticleSystem>().emission;
        theParticleSystemsRateCurve              = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 50) + 0;
        theParticleSystem.rate                   = theParticleSystemsRateCurve;

        theParticleSystem                        = leftFrontThrust.GetComponent <ParticleSystem>().emission;
        theParticleSystemsRateCurve              = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 50) + 0;
        theParticleSystem.rate                   = theParticleSystemsRateCurve;


        /*
         * //Try to apply some amount of rightward velocity
         * angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (transform.right.x, transform.right.y)));
         * if (angleDifference < 90) {
         *
         *      velocityToCheck = moveAngleInput * (1 - angleDifference / 90) * strafeAccel * Time.deltaTime;
         *
         *      //float currentSpeed = myVelocity.y * transform.right.y + myVelocity.x * transform.right.x;
         *      float newSpeed = (myVelocity.y + velocityToCheck.y) * transform.right.y + (myVelocity.x + velocityToCheck.x) * transform.right.x;
         *
         *      //Don't add it if it puts you over the speed limit
         *      if (newSpeed < strafeSpeedLimit * (1 - angleDifference / 90)) {
         *              velocityToAdd += velocityToCheck;
         *      }
         * }*/

        angleDifference = (Vector2.Angle(moveAngleInput, new Vector2(transform.right.x, transform.right.y)));
        if (angleDifference < 90)
        {
            velocityToAdd += moveAngleInput * (1 - angleDifference / 90) * strafeAccel * Time.deltaTime;
        }

        theParticleSystem                        = leftFrontThrust.GetComponent <ParticleSystem>().emission;
        theParticleSystemsRateCurve              = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 50) + 0;
        theParticleSystem.rate                   = theParticleSystemsRateCurve;

        /*
         * //Try to apply some amount of leftward velocity
         * angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (-transform.right.x, -transform.right.y)));
         * if (angleDifference < 90) {
         *
         *      velocityToCheck = moveAngleInput * (1 - angleDifference / 90) * strafeAccel * Time.deltaTime;
         *
         *      //float currentSpeed = myVelocity.y * -transform.right.y + myVelocity.x * -transform.right.x;
         *      float newSpeed = (myVelocity.y + velocityToCheck.y) * -transform.right.y + (myVelocity.x + velocityToCheck.x) * -transform.right.x;
         *      //Debug.Log (newSpeed);
         *      //Don't add it if it puts you over the speed limit
         *      if (newSpeed < strafeSpeedLimit * (1 - angleDifference / 90)) {
         *              velocityToAdd += velocityToCheck;
         *      }
         * }*/

        angleDifference = (Vector2.Angle(moveAngleInput, new Vector2(-transform.right.x, -transform.right.y)));
        if (angleDifference < 90)
        {
            velocityToAdd += moveAngleInput * (1 - angleDifference / 90) * strafeAccel * Time.deltaTime;
        }

        //Increase particles to front right thrusts
        theParticleSystem                        = rightFrontThrust.GetComponent <ParticleSystem>().emission;
        theParticleSystemsRateCurve              = theParticleSystem.rate;
        theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 50) + 0;
        theParticleSystem.rate                   = theParticleSystemsRateCurve;


        //IMPROVE
        //Ship accelerates slower at speed, similar to a plane
        //Debug.Log(1.0f - (myVelocity.magnitude / maxSpeedMagnitude));

        //velocityToAdd *= 1.5f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude - 4), 0.5f, 1f);//Old one
        //velocityToAdd *= 1.5f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude - 4), 0.5f, 1f);//Better working one

        //velocityToAdd *= 2f - Mathf.Clamp( (myVelocity.magnitude  / maxSpeedMagnitude) * 1.5f, 1f, 1.5f);//Other decent alternative

        //Slow acceleration
        velocityToAdd *= (1 - percentageFrostSlow);

        gameObject.GetComponent <Rigidbody2D> ().velocity += velocityToAdd;       //Add the velocity
        //Debug.Log (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude);

        velocityToAdd = Vector2.zero;        //Reset the velocity to add value, ready for the next update

        //If the ship's velocity is above the max speed, it is reduced to the max speed instead.
        if (gameObject.GetComponent <Rigidbody2D> ().velocity.magnitude > /*maxSpeedMagnitude*/ speedLimitToUse)
        {
            gameObject.GetComponent <Rigidbody2D> ().velocity = gameObject.GetComponent <Rigidbody2D> ().velocity.normalized *speedLimitToUse;
        }

        //Debug.Log (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude);

        //UNSURE

        /*if (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude < 10f && moveAngleInput.magnitude < 0.5f) {
         *      gameObject.GetComponent<Rigidbody2D> ().drag = originalDrag + (1 - (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude / 10)) * 1.2f;
         *      //gameObject.GetComponent<Rigidbody2D> ().drag = originalDrag + 1;
         * } else
         *      gameObject.GetComponent<Rigidbody2D> ().drag = originalDrag;
         */


        /*//stuff for recharging boost
         * remainingBoostRechargeDelay -= Time.deltaTime;
         * if (remainingBoostRechargeDelay <= 0) {
         *      remainingBoostDuration += (maxBoostDuration / fullBoostRechargeTime) * Time.deltaTime;
         *      if (remainingBoostDuration > maxBoostDuration)
         *              remainingBoostDuration = maxBoostDuration;
         * }*/
    }
Example #12
0
    private void checkInput()
    {
        FlipAddingScoreText();
        var move = new Vector3(joystick.Horizontal(), 0);

        if (waitTimeForEffector >= 0)
        {
            waitTimeForEffector -= Time.deltaTime;
        }
        if (curTimeCDSkill > 0 && !isSkillActive)
        {
            curTimeCDSkill -= Time.deltaTime;
            if (curTimeDurationSkill > 0)
            {
                curTimeDurationSkill -= Time.deltaTime;
                buffMoveSpeed        *= 1.0003f;
                buffjumpForce        *= 1.0003f;
            }
            else
            {
                buffMoveSpeed = 1f;
                buffjumpForce = 1f;
            }
            countDownText_BuffUI.text     = curTimeCDSkill.ToString(curTimeCDSkill < 10f ? "#" : "##");
            rollerCoverBuffImg.fillAmount = curTimeCDSkill / cooldownSkill;
            if (curTimeCDSkill <= 0)
            {
                countDownObj_BuffUI.SetActive(false);
            }
        }
        else if (curTimeCDSkill > 0 && isSkillActive)
        {
            isSkillActive = false;
        }

        if (((Input.GetKeyDown(KeyCode.Space) || jumpBtn.pressed) && !anim.GetBool("IsJump") && isGrounded) && curJumpCount <= 0)
        {
            curJumpCount++;
            sfxCreator.Create(jump, 0.3f, 1f);
            PerformJumpPlus();
        }

        if ((!jumpBtn.pressed && curJumpCount > 0) && isGrounded)
        {
            curJumpCount = 0;
        }

        if ((Input.GetKeyDown(KeyCode.E) || pickupBtn.pressed) && !isPickup)
        {
            anim.SetTrigger("Pickup");
            photonView.RPC("PickUpAnimationTrigger", PhotonTargets.Others);
        }

        WaitForDestroyTrashInHand();

        if ((Input.GetKeyDown(KeyCode.Mouse0) || throwBtn.pressed) && !isPickup)
        {
            anim.SetTrigger("Throw");
            sfxCreator.Create(throwTrash, 1f, 1f);
            photonView.RPC("ThrowAnimationTrigger", PhotonTargets.Others);
        }
        else if ((Input.GetKeyDown(KeyCode.Mouse0) || throwBtn.pressed) && isPickup)
        {
            anim.SetTrigger("Throw");
            sfxCreator.Create(throwTrash, 1f, 1f);
            for (int i = 0; i < trashImg.Length; i++)
            {
                if (trashImg[i].activeSelf)
                {
                    trashImg[i].SetActive(false);
                    photonView.RPC("ShowTrash", PhotonTargets.OthersBuffered, i, trashImg[i].activeSelf);
                }
            }
            photonView.RPC("ThrowAnimationTrigger", PhotonTargets.Others);
            ThrowTrash();
            isPickup = false;
        }

        if (anim.GetBool("IsWalk") && (move.x >= -0.15f || move.x <= 0.15f))
        {
            anim.SetBool("IsWalk", false);
            photonView.RPC("WalkAnimationFalse", PhotonTargets.Others);
        }

        if (Input.GetKey(KeyCode.D) || joystick.Horizontal() > 0)
        {
            transform.position += move * (moveSpeed * buffMoveSpeed) * Time.deltaTime;
            if (!anim.GetBool("IsWalk") && move.x > 0)
            {
                anim.SetBool("IsWalk", true);
                photonView.RPC("WalkAnimationTrue", PhotonTargets.Others);
            }

            if (transform.localScale.x < 0)
            {
                isFacingRight                = !isFacingRight;
                scale.x                     *= -1;
                textObjScale.x              *= -1;
                transform.localScale         = scale;
                textObj.transform.localScale = textObjScale;
                photonView.RPC("OnSpriteFlip", PhotonTargets.Others);
            }
        }
        else if (Input.GetKey(KeyCode.A) || joystick.Horizontal() < 0)
        {
            transform.position += move * (moveSpeed * buffMoveSpeed) * Time.deltaTime;
            if (!anim.GetBool("IsWalk") && move.x < 0)
            {
                anim.SetBool("IsWalk", true);
                photonView.RPC("WalkAnimationTrue", PhotonTargets.Others);
            }

            if (transform.localScale.x > 0)
            {
                isFacingRight                = !isFacingRight;
                scale.x                     *= -1;
                textObjScale.x              *= -1;
                transform.localScale         = scale;
                textObj.transform.localScale = textObjScale;
                photonView.RPC("OnSpriteFlip", PhotonTargets.Others);
            }
        }
    }
    void Update()
    {
        if (isDead)
        {
            playerState = PlayerState.dead;
            animator.SetTrigger("isDead");
            Invoke("gameOver", 4);
            //GetComponent<Collider> ().enabled = false;
        }
        else if (isFall)
        {
            animator.SetTrigger("isFall");
            Camera.main.GetComponent <Rotate_CamCtrl> ().fix = true;
            Invoke("gameOver", 1);
        }
        else
        {
            Vector3 moveDir = Vector3.zero;

            if (isMobile)
            {
                moveDir.x = joystick.Horizontal();
                moveDir.z = joystick.Vertical();
            }
            else
            {
                h       = Input.GetAxis("Horizontal");
                v       = Input.GetAxis("Vertical");
                moveDir = (Vector3.forward * v) + (Vector3.right * h);
            }

            v = moveDir.z;
            h = moveDir.x;

            if (v >= 0.1f || v <= -0.1f || h >= 0.1f || h <= -0.1f)
            {
                playerState = PlayerState.run;
                animator.SetBool("isRun", true);
                moveSpeed = 2.5f;
            }
            else
            {
                //Debug.Log ("Doing Nothing");
                playerState = PlayerState.idle;
                animator.SetBool("isRun", false);
                moveSpeed = 0f;
            }

            if (moveDir != Vector3.zero)
            {
                tr.rotation = Quaternion.LookRotation(moveDir);
            }

            if (isCombo)
            {
                playerState = PlayerState.attack;

                comboTimer -= Time.deltaTime;

                if (comboTimer <= 0)
                {
                    isCombo    = false;
                    comboTimer = 0;
                    comboIndex = 0;
                    motionEnd();
                }
            }

            if (isDelay)
            {
                animator.SetBool("isRun", false);
                moveSpeed = 0f;
            }
            else
            {
                tr.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
                camPos.transform.position = new Vector3(tr.position.x - 0.01f, tr.position.y + 1.87f, tr.position.z - 2.64f);
            }

            //Collider[] nearObj = Physics.OverlapSphere (transform.position, 2.5f);

            /*
             * if (autoAttack)
             * {
             *      isAttack = true;
             * }
             * else
             * {
             *      isAttack = false;
             * }
             */

            /*
             * // isSkill_1 : DualSword Skill (Buff)
             * if (isSkill_1)
             * {
             *      this.gameObject.GetComponent<Re_ItemMgr2>().Buff(0, true);
             *      this.gameObject.GetComponent<Re_ItemMgr2>().Buff(1, true);
             *      Buff_Effect_body.SetActive(true);
             *      Buff_L_Hand.SetActive(true);
             *      Buff_R_Hand.SetActive(true);
             *      skill_1Timer += Time.deltaTime;
             *      if (skill_1Timer > 8f)
             *      {
             *              isSkill_1 = false;
             *      }
             * }
             *
             * else
             * {
             *      this.gameObject.GetComponent<Re_ItemMgr2>().Buff(0, false);
             *      this.gameObject.GetComponent<Re_ItemMgr2>().Buff(1, false);
             *      Buff_Effect_body.SetActive(false);
             *      Buff_L_Hand.SetActive(false);
             *      Buff_R_Hand.SetActive(false);
             * }
             *
             * // isSkill_1 : GreatSword Skill (PowerSmash)
             * if (isSkill)
             * {
             *      if (this.gameObject.GetComponent<Re_ItemMgr2>().meleIndex == 0)
             *      {
             *              skillTimer += Time.deltaTime;
             *              skill_1Timer = 0;
             *              if (skillTimer > 3f)
             *              {
             *                      isSkill = false;
             *                      isSkill_1 = true;
             *                      skillTimer = 0;
             *              }
             *      }
             * }
             *
             * //////// Guard //////////
             * else if (isGuard)
             * {
             *      //_animation.CrossFade (anim.guard.name, 0.3f);
             *      animator.SetBool("isGuard", true);
             *      if (isBreak)
             *      {
             *              animator.SetTrigger("guardBreak");
             *              GuardMgr.GetComponent<ReGuardBtnMgr>().isBreak = true;
             *              playerShield.GetComponent<Re_shield>().DisableShield();
             *              isBreak = false;
             *      }
             *
             * }
             * else
             * {
             *      animator.SetBool("isGuard", false);
             *      if (playerShield != null)
             *      {
             *              playerShield.GetComponent<Re_shield>().DisableShield();
             *      }
             *      if (isAttack)
             *      {
             *
             *              //this.GetComponent<Re_ItemMgr2> ().ActiveWeaponCollider (true);
             *
             *              moveSpeed = 1.0f;
             *              animator.SetBool("isAttack", true);
             *              attackTimer += 1;
             *              if (attackTimer == 20)
             *              {
             *                      isAttack = false;
             *                      attackTimer = 0;
             *              }
             *      }
             *      else if (manualAttack)
             *      {
             *              animator.SetTrigger("manualAttack");
             *              manualAttack = false;
             *      }
             *      else
             *      {
             *
             *              //this.GetComponent<Re_ItemMgr2> ().ActiveWeaponCollider (false);
             *              animator.SetBool("isAttack", false);
             *
             *              if (v >= 0.1f)
             *              {
             *                      animator.SetBool("isRun", true);
             *                      animator.SetBool("isMove", false);
             *                      if (isSkill_1)
             *                              moveSpeed = 8f;
             *                      else if (attacking)
             *                              moveSpeed = 0.0f;
             *                      else
             *                              moveSpeed = 5.5f;
             *              }
             *              else if (v <= -0.1f)
             *              {
             *                      animator.SetBool("isRun", false);
             *                      animator.SetBool("isMove", true);
             *                      if (isSkill_1)
             *                              moveSpeed = 7f;
             *                      else if (attacking)
             *                              moveSpeed = 0.0f;
             *                      else
             *                              moveSpeed = 4.0f;
             *              }
             *              else if (h >= 0.1f || h <= -0.1f)
             *              {
             *                      animator.SetBool("isRun", false);
             *                      animator.SetBool("isMove", true);
             *              }
             *              else
             *              {
             *                      //Debug.Log ("Doing Nothing");
             *                      animator.SetBool("isMove", false);
             *                      animator.SetBool("isRun", false);
             *              }
             *
             *      }
             *      tr.Translate(moveDir * Time.deltaTime * moveSpeed, Space.Self);
             *
             * }
             * }
             */
            this.GetComponent <Rigidbody> ().isKinematic = false;

            if (playerHp / initHp < 0.2f)
            {
                imgHpbar.color = Color.red;
            }
            else if (playerHp / initHp < 0.5f)
            {
                imgHpbar.color = Color.yellow;
            }
            else
            {
                imgHpbar.color = Color.green;
            }
            imgHpbar.fillAmount = playerHp / initHp;
        }
    }