Ejemplo n.º 1
0
    void Update()
    {
        // Moving
        //PlayerMovement.MSV_Update();

        // Shooting
        if (MSV_Input.GetActionPressed(MSV_Action.Fire1))
        {
            Vector3    facing   = PlayerMovement.GetFacing();
            Vector3    spawnPos = transform.TransformPoint(Capsule.center + Capsule.height * 0.25f * Vector3.up) + facing * (Capsule.radius + 0.1f);
            Quaternion spawnDir = Quaternion.LookRotation(facing, Vector3.up);
            Instantiate <GameObject>(Projectile, spawnPos, spawnDir);
        }

        if (MSV_Input.GetActionPressed(MSV_Action.Fire2))
        {
        }
    }
Ejemplo n.º 2
0
    public void Move_Update()
    {
        var x = MSV_Input.GetAxis(MSV_Axis.Horizontal);
        var y = MSV_Input.GetAxis(MSV_Axis.Vertical);

        // if either direction is more than 0.1
        if (x * x + y * y > 0.01f)
        {
            //Accelerate
            float dir = Mathf.Atan2(y, x) / DIR_SCALE;
            dir  = Mathf.Floor(dir + 0.5f);
            dir *= DIR_SCALE;
            Vector3 accelDir = Mathf.Cos(dir) * Vector3.right + Mathf.Sin(dir) * Vector3.forward;
            float   mag      = Mathf.Sqrt(x * x + y * y);
            RB.AddForce(Acceleration * mag * accelDir, ForceMode.Acceleration);
            Facing = accelDir;
        }
        else
        {
            if (RB.velocity.sqrMagnitude > 0.1f)
            {
                // Decelerate
                Vector3 horizontalVel = RB.velocity;
                horizontalVel.y = 0.0f;
                horizontalVel.Normalize();
                RB.AddForce(Deceleration * -horizontalVel, ForceMode.Acceleration);
            }
        }
        UpdateFloorDistance();

        if (MSV_Input.GetActionPressed(MSV_Action.Jump) && IsOnGround)
        {
            RB.AddForce(JumpVelocity * Vector3.up, ForceMode.VelocityChange);
        }

        // Limit Max Velocity
        if (RB.velocity.x * RB.velocity.x + RB.velocity.z * RB.velocity.z > MaxVelocity * MaxVelocity)
        {
            var horizontalVel = new Vector2(RB.velocity.x, RB.velocity.z);
            horizontalVel = horizontalVel.normalized * MaxVelocity;
            RB.velocity   = new Vector3(horizontalVel.x, RB.velocity.y, horizontalVel.y); // those two Ys are not a typo
        }
    }