예제 #1
0
    public CritterInputPacket UpdateTick()
    {
        var result = thisTickFrame;

        lastTickFrame = thisTickFrame;
        return(result);
    }
예제 #2
0
    Quaternion UpdateOrientation(CritterInputPacket packet)
    {
        var mouseX = packet.MouseX * config.KeyRollSensitivity;

        _rollDegrees -= mouseX;
        _rollDegrees  = Mathf.Clamp(_rollDegrees, -config.RollClampDegrees, config.RollClampDegrees);

        float yaw = 0f;

        if (packet.leftward)
        {
            yaw -= config.MouseYawSensitivity;
        }
        if (packet.rightward)
        {
            yaw += config.MouseYawSensitivity;
        }
        _yawDegress += yaw * config.MouseYawSensitivity;
        _yawDegress += mouseX * config.RollYawTrim;

        _pitchDegrees -= packet.MouseY * config.MousePitchSensitivity;
        _pitchDegrees  = Mathf.Clamp(_pitchDegrees, -config.PitchClampDegrees, config.PitchClampDegrees);

        return(Quaternion.Euler(_pitchDegrees, _yawDegress, _rollDegrees));
    }
예제 #3
0
    public CritterInputPacket UpdateImmediate()
    {
        float mouseX = Input.GetAxis("Mouse X");
        float mouseY = Input.GetAxis("Mouse Y");

        var thisImmediateFrame = new CritterInputPacket {
            headOrientation = updateOrientation(),
            forward         = Input.GetKey(KeyCode.W),
            backward        = Input.GetKey(KeyCode.S),
            leftward        = Input.GetKey(KeyCode.A),
            rightward       = Input.GetKey(KeyCode.D),
            jump            = Input.GetKey(KeyCode.Space),
            shoot           = Input.GetMouseButton(0),
            MouseX          = mouseX,
            MouseY          = mouseY,
        };

        thisTickFrame.forward         = immediateInputToTick(thisTickFrame.forward, lastTickFrame.forward, thisImmediateFrame.forward);
        thisTickFrame.backward        = immediateInputToTick(thisTickFrame.backward, lastTickFrame.backward, thisImmediateFrame.backward);
        thisTickFrame.leftward        = immediateInputToTick(thisTickFrame.leftward, lastTickFrame.leftward, thisImmediateFrame.leftward);
        thisTickFrame.rightward       = immediateInputToTick(thisTickFrame.rightward, lastTickFrame.rightward, thisImmediateFrame.rightward);
        thisTickFrame.jump            = immediateInputToTick(thisTickFrame.jump, lastTickFrame.jump, thisImmediateFrame.jump);
        thisTickFrame.shoot           = immediateInputToTick(thisTickFrame.shoot, lastTickFrame.shoot, thisImmediateFrame.shoot);
        thisTickFrame.headOrientation = thisImmediateFrame.headOrientation;
        thisTickFrame.MouseX          = mouseX;
        thisTickFrame.MouseY          = mouseY;

        return(thisImmediateFrame);
    }
예제 #4
0
    public CritterInputGrabber(float mouseSensitivity = 4f)
    {
        this.mouseSensitivity = mouseSensitivity;

        thisTickFrame = new CritterInputPacket {
            headOrientation = Quaternion.identity
        };

        lastTickFrame = thisTickFrame;
    }
예제 #5
0
        public void SendUpdateCritterInput(NetworkPlayer owner, CritterInputPacket critterInputPacket)
        {
            var message = new CritterInputPacketMessage()
            {
                ID = owner.ID,
                critterInputPacket = critterInputPacket
            };

            SendMessageToClients(GameMsgType.UpdateCritterInput, message, false);
        }
예제 #6
0
    public CritterStatePacket UpdateTick(CritterInputPacket packet)
    {
        hasHadAnyInput |= packet.forward || packet.jump;
        UpdateState();
        DoMove(packet);
        TryPoop(packet);

        return(new CritterStatePacket
        {
            position = critter.transform.position,       // TODO mmm this feels weird
            velocity = rb.velocity,
            headOrientation = critter.transform.rotation // TODO prob dont need this
        });
    }
예제 #7
0
        internal void PostCritterInputPacket(CritterInputPacket obj)
        {
            if (Connection == null)
            {
                return;
            }

            Debug.Log("PostCritterInputPacket Player#" + ID + " " + obj);

            Connection.SendUnreliable(GameMsgType.UpdateCritterInput, new CritterInputPacketMessage()
            {
                ID = ID,
                critterInputPacket = obj
            });
        }
예제 #8
0
파일: Player.cs 프로젝트: PawkaHub/ggj2019
 internal void SetInputPacket(CritterInputPacket critterInputPacket)
 {
     CritterController.InputPacketOveride = critterInputPacket;
 }
예제 #9
0
 public void UpdateImmediate(CritterInputPacket packet)
 {
     cameraBobT += rb.velocity.WithY(0).magnitude * 0.05f;
     Head.transform.rotation             = packet.headOrientation;
     childCamera.transform.localPosition = 0.02f * cameraBob(cameraBobT);
 }
예제 #10
0
    public CritterStatePacket UpdateTick(CritterInputPacket packet)
    {
        bool walking = false;

        rb.velocity += Physics.gravity * config.gravityMult * Time.fixedDeltaTime;

        var flatVel = rb.velocity.WithY(0);
        var fwd     = Head.transform.forward.WithY(0).normalized;
        var right   = Head.transform.right.WithY(0).normalized;

        var desiredVel = Vector3.zero;

        if (packet.forward)
        {
            desiredVel += fwd;
            walking     = true;
        }
        else if (packet.backward)
        {
            desiredVel -= fwd;
            walking     = true;
        }

        if (packet.rightward)
        {
            desiredVel += right;
            walking     = true;
        }
        else if (packet.leftward)
        {
            desiredVel -= right;
            walking     = true;
        }

        desiredVel = desiredVel.normalized * config.maxSpeed;

        if (walking)
        {
            flatVel = Vector3.Lerp(flatVel, desiredVel, 1f / config.accelLag);
        }
        else
        {
            flatVel *= config.autoDecel;
        }

        if (flatVel.sqrMagnitude > config.maxSpeed * config.maxSpeed)
        {
            flatVel = flatVel.normalized * config.maxSpeed;
        }

        rb.velocity = flatVel + Vector3.up * rb.velocity.y;

        if (packet.jump && grounded > 0)
        {
            grounded    = 0;
            rb.velocity = rb.velocity.WithY(config.jumpVelY);
            audioManager.PlayJumpSound();
        }

        var newPosition = rb.position + rb.velocity * Time.fixedDeltaTime;

        if (grounded > 0)
        {
            grounded--;
        }

        var hits    = Physics.SphereCastAll(newPosition, suspensionRadius, Vector3.down, config.extraHeight, LayerMask.GetMask("Default"));
        var hitInfo = findImportantHit(hits);

        if (hitInfo.HasValue)
        {
            var fixedCastPos = newPosition + Vector3.down * hitInfo.Value.distance;
            newPosition  = fixedCastPos + Vector3.up * config.extraHeight;
            rb.velocity  = rb.velocity.WithY(0);
            rb.velocity += (newPosition - rb.position) * 10f;

            grounded = 2;
        }

        launcher.Update(packet.shoot, critter.transform.position, packet.headOrientation * Vector3.forward);

        return(new CritterStatePacket {
            position = newPosition,
            velocity = rb.velocity,
            headOrientation = Head.transform.rotation
        });
    }
예제 #11
0
    void DoMove(CritterInputPacket packet)
    {
        var orientation = UpdateOrientation(packet);

        rb.MoveRotation(orientation);

        var angleOfAttack = Mathf.Acos(Vector3.Dot(rb.velocity.normalized, critter.transform.forward.normalized)) * Mathf.Rad2Deg;

        float locForwardVel = critter.transform.InverseTransformDirection(rb.velocity).z;
        float drag          = config.DragMagic * (Mathf.Pow(locForwardVel, 2) / 2) * angleOfAttack;

        var sign = (Quaternion.LookRotation(Vector3.forward, Vector3.up) * critter.transform.forward.normalized).y;
        var signedAngleOfAttack = angleOfAttack;

        if (sign < 0)
        {
            signedAngleOfAttack *= -1;
        }

        if (packet.jump)
        {
            float flapForce = Mathf.Cos(Time.time * config.FlapFrequency) * config.FlapPower;
            flapForce = Mathf.Abs(flapForce);
            var flapThrustToLiftRatio = config.FlapThrustToLiftRatioPressingNotPressingW;
            if (currentState == STATE.FLYING)
            {
                flapThrustToLiftRatio = packet.forward ? config.FlapThrustToLiftRatioPressingW : config.FlapThrustToLiftRatioPressingNotPressingW;
            }
            else
            {
                audioManager.PlayJumpSound();
            }
            rb.AddForce(critter.transform.forward * flapForce * flapThrustToLiftRatio);
            rb.AddForce(critter.transform.up * flapForce * (1 - flapThrustToLiftRatio));
        }

        var dragVector = rb.velocity * -drag;

        if (Vector3.Magnitude(dragVector) < Mathf.Infinity)
        {
            rb.AddForce(dragVector);
        }

        float lift       = (Mathf.Pow(locForwardVel, 2) * config.LiftMagic * signedAngleOfAttack) / 2;
        var   liftVector = critter.transform.up * lift;

        rb.AddForce(liftVector);

        if (hasHadAnyInput)
        {
            rb.AddForce(Physics.gravity, ForceMode.Acceleration);
        }

        // janky, no science glide bs
        var fallVelocity = rb.velocity.y;
        var glideRatio   = lift / drag;

        if (!Collided && fallVelocity < 0 && glideRatio < 0)
        {
            var forwardGlide = fallVelocity * glideRatio * config.GlideMagic;
            rb.AddForce(critter.transform.forward * forwardGlide, ForceMode.VelocityChange);
        }
    }
예제 #12
0
 void TryPoop(CritterInputPacket packet)
 {
     launcher.Update(packet.shoot, critter.transform.position, -critter.transform.up);
 }
예제 #13
0
 public void UpdateImmediate(CritterInputPacket packet)
 {
     hasHadAnyInput |= packet.forward || packet.jump;
     // TODO not sure what to put in here
 }