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

        lastTickFrame = thisTickFrame;
        return(result);
    }
Beispiel #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));
    }
Beispiel #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);
    }
Beispiel #4
0
    public CritterInputGrabber(float mouseSensitivity = 4f)
    {
        this.mouseSensitivity = mouseSensitivity;

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

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

            SendMessageToClients(GameMsgType.UpdateCritterInput, message, false);
        }
Beispiel #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
        });
    }
        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
            });
        }
Beispiel #8
0
 internal void SetInputPacket(CritterInputPacket critterInputPacket)
 {
     CritterController.InputPacketOveride = critterInputPacket;
 }
Beispiel #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);
 }
Beispiel #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
        });
    }
Beispiel #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);
        }
    }
Beispiel #12
0
 void TryPoop(CritterInputPacket packet)
 {
     launcher.Update(packet.shoot, critter.transform.position, -critter.transform.up);
 }
Beispiel #13
0
 public void UpdateImmediate(CritterInputPacket packet)
 {
     hasHadAnyInput |= packet.forward || packet.jump;
     // TODO not sure what to put in here
 }