private bool ProcessItem
        (
            ref Entity entity,
            ref StVelocity velocity,
            ref DefStJumpSettings setting,
            ref DefStRunInput runInput,
            ref DefStJumpInput input,
            ref DefStWallJumpProcessData process,
            ref CharacterControllerState state,
            Transform transform
        )
        {
            var action = input.State == InputState.Down && !MvUtils.OnGround(state, velocity) && Time.time > process.TimeBeforeNextWJ;

            if (!action)
            {
                return(false);
            }

            var originalVelocity = velocity.Value;
            var fwd       = transform.forward;
            var pos       = transform.position + new Vector3(0, 0.4f + 0.1f); // hardcoded value (stepoffset)
            var rot       = transform.rotation;
            var rd        = 0.3f + 0.075f;                                    // (radius)
            var sw        = 0.07f + 0.025f;                                   // hardcoded value (skinwidth)
            var height    = 2f - 0.4f;                                        // harcoded value (height and stepOffset)
            var subheight = (height * 0.75f) - 0.005f;

            CPhysicSettings.Active.SetGlobalCollision(transform.gameObject, false);

            var direction = (Vector3)SrtComputeDirection(fwd, rot, runInput.Direction);
            var rayTrace  = UtilityWallRayTrace.RayTrace(ref direction, ref pos, ref rd, ref sw, ref height, ref subheight, transform.GetComponent <Collider>());

            Debug.DrawRay(rayTrace.point, rayTrace.normal, Color.red, 10);

            CPhysicSettings.Active.SetGlobalCollision(transform.gameObject, true);

            var success = rayTrace.normal != Vector3.zero && Mathf.Abs(rayTrace.normal.y) < 0.2f;

            if (success)
            {
                rayTrace.normal = rayTrace.normal.ToGrid(1).normalized;

                velocity.Value = RaycastUtilities.SlideVelocityNoYChange(velocity.Value, rayTrace.normal);

                velocity.Value.y = math.max(math.min(velocity.Value.y + 6.5f, 12f), 0);

                var previousVelocity = velocity.Value;
                var bounceDir        = rayTrace.normal * 6f;
                var minSpeed         = bounceDir.magnitude;

                velocity.Value += bounceDir;

                var flatVelocity = velocity.Value.ToGrid(1);
                var oldY         = velocity.Value.y;

                velocity.Value = Vector3.ClampMagnitude(flatVelocity, Mathf.Max(previousVelocity.magnitude, minSpeed));

                velocity.Value.y = oldY;

                process.TimeBeforeNextWJ = Time.time + DefaultCooldown;

                input.TimeBeforeResetState = -1f;
                input.State = InputState.None;

                BroadcastNewEntity(PostUpdateCommands, true);
                PostUpdateCommands.AddComponent(new DefStWallJumpEvent(Time.time, Time.frameCount, entity, originalVelocity, rayTrace.normal));

                MvDelegateEvents.InvokeCharacterWalljump(entity);
            }

            return(success);
        }
Пример #2
0
        private bool ProcessItem
        (
            ref Entity entity,
            ref StVelocity velocity,
            ref DefStJumpSettings setting,
            ref DefStRunInput runInput,
            ref DefStJumpInput input,
            ref DefStJumpProcessData process,
            ref CharacterControllerState state,
            Transform transform
        )
        {
            if (MvUtils.OnGround(state, velocity))
            {
                process.ComboCtx = 0;
            }

            if (input.ContinueJump == 0)
            {
                process.NeedToChain = 0;
            }

            var inputCanJump = input.State == InputState.Down || (input.ContinueJump == 1 && process.NeedToChain == 1);
            var doJump       = inputCanJump && (process.ComboCtx < setting.MaxCombo && process.CooldownBeforeNextJump <= 0f) &&
                               (MvUtils.OnGround(state, velocity) || process.ComboCtx > 0);
            var airJump = doJump && !state.IsGrounded() && !state.IsSliding();

            if (input.TimeBeforeResetState <= 0f)
            {
                input.State = InputState.None;
            }

            process.CooldownBeforeNextJump -= Time.deltaTime;
            input.TimeBeforeResetState     -= Time.deltaTime;

            // We expect the developpers to check for staminas or things like that for this command.
            DiffuseCommand(m_CmdDoJump, m_CmdDoJumpResult, doJump, CmdState.Begin);

            doJump = GetCmdResult(m_CmdDoJumpResult);
            if (!doJump)
            {
                return(false);
            }

            var direction   = SrtComputeDirection(transform.forward, transform.rotation, runInput.Direction);
            var strafeAngle = SrtGetStrafeAngleNormalized(direction, velocity.Value);

            if (math.all(runInput.Direction == float2.zero))
            {
                strafeAngle *= 0.5f;
            }

            if (input.State == InputState.Down)
            {
                process.NeedToChain = 1;
            }

            velocity.Value.y = math.max(velocity.Value.y, 0);
            if (!airJump)
            {
                var motor = transform.GetComponent <CharacterControllerMotor>();

                velocity.Value += Vector3.up * (setting.JumpPower * (input.State != InputState.Down ? 0.75f : 1f));
                //if (motor.Momentum.y > 0) velocity.Value += Vector3.up * (motor.Momentum.normalized.y * 6f);
            }
            else
            {
                velocity.Value = Vector3.up * setting.JumpPower;
            }

            if (airJump)
            {
                velocity.Value = math.lerp(velocity.Value, SrtAirDash(velocity.Value, direction), 1f);
            }
            else if (input.State != InputState.Down)
            {
                velocity.Value += (Vector3)(direction * (strafeAngle * 5f));

                var oldY      = velocity.Value.y;
                var currSpeed = velocity.Value.ToGrid(1).magnitude;
                var newSpeed  = math.min(currSpeed + strafeAngle * 2f, math.max(currSpeed, 18f));
                velocity.Value   = velocity.Value.ToGrid(1).normalized *newSpeed;
                velocity.Value.y = oldY;
            }
            else
            {
                var oldY = velocity.Value.y;
                //velocity.Value = velocity.Value.ToGrid(1).normalized * (velocity.Value.ToGrid(1).magnitude - 2.5f);
                velocity.Value.y = oldY;
            }

            input.TimeBeforeResetState = -1f;
            input.State = InputState.Pressed;

            process.ComboCtx++;
            process.CooldownBeforeNextJump = 0.1f;

            // We except developpers to just clean the pre-command phase, and not applying things like reducing stamina...
            DiffuseCommand(m_CmdDoJump, m_CmdDoJumpResult, true, CmdState.End);

            // Send event to clients
            BroadcastNewEntity(PostUpdateCommands, true);
            PostUpdateCommands.AddComponent(new DefStJumpEvent(Time.time, Time.frameCount, entity));

            MvDelegateEvents.InvokeCharacterJump(entity);

            return(true);
        }