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); }
private bool ProcessItem ( ref Entity entity, ref StVelocity velocity, ref DefStDodgeOnGroundSettings setting, ref DefStRunInput runInput, ref DefStDodgeInput input, ref DefStWallDodgeProcessData process, ref DefStDodgeOnGroundProcessData groundProcess, CharacterControllerMotor motor ) { var action = input.State != InputState.None && !MvUtils.OnGround(motor, velocity) && Time.time > process.TimeBeforeNextWD; DiffuseCommand(m_CmdDoDodge, m_CmdDoDodgeResult, action, CmdState.Begin); if (!m_CmdDoDodgeResult.GetComponentData <EntityCommandResult>().AsBool()) { DiffuseCommand(m_CmdDoDodge, m_CmdDoDodgeResult, action, CmdState.End); return(false); } var originalVelocity = velocity.Value; var fwd = motor.transform.forward; var pos = motor.transform.position + new Vector3(0, motor.CharacterController.stepOffset + 0.1f); var rot = motor.transform.rotation; var rd = motor.CharacterController.radius + 0.075f; var sw = motor.CharacterController.skinWidth + 0.025f; var height = motor.CharacterController.height - motor.CharacterController.stepOffset; var subheight = (height * 0.75f) - 0.005f; CPhysicSettings.Active.SetGlobalCollision(motor.gameObject, false); var direction = (Vector3)SrtComputeDirection(fwd, rot, runInput.Direction); direction = (velocity.Value.ToGrid(1).normalized + direction * 2).normalized; var rayTrace = UtilityWallRayTrace.RayTrace(ref direction, ref pos, ref rd, ref sw, ref height, ref subheight, motor.CharacterController); CPhysicSettings.Active.SetGlobalCollision(motor.gameObject, true); var success = rayTrace.normal != Vector3.zero && Mathf.Abs(rayTrace.normal.y) < 0.2f; if (success) { rayTrace.normal = rayTrace.normal.ToGrid(1).normalized; var reflected = (Vector3.Reflect(direction, rayTrace.normal) + rayTrace.normal).normalized; var oldY = velocity.Value.y; var dirInertie = (reflected * (velocity.Value.magnitude + 1)) + rayTrace.normal * 3.5f; dirInertie = RaycastUtilities.SlideVelocityNoYChange(velocity.Value, rayTrace.normal) + rayTrace.normal * 10; var minSpeed = Mathf.Max(velocity.Value.ToGrid(1).magnitude + setting.AdditiveSpeed, setting.MinSpeed); velocity.Value = dirInertie.ToGrid(1).normalized *(minSpeed); velocity.Value.y = Mathf.Max(oldY + 2, 0); process.TimeBeforeNextWD = Time.time + DefaultCooldown; input.TimeBeforeResetState = -1f; input.State = InputState.None; groundProcess.CooldownBeforeNextDodge = 0.25f; //groundProcess.InertieDelta = 0.5f; groundProcess.Direction = dirInertie.normalized; BroadcastNewEntity(PostUpdateCommands, true); PostUpdateCommands.AddComponent(new DefStWallJumpEvent(Time.time, Time.frameCount, entity, originalVelocity, rayTrace.normal)); } DiffuseCommand(m_CmdDoDodge, m_CmdDoDodgeResult, action, CmdState.End); return(success); }