Борьба с мульти осиC#

Место общения программистов C#
Ответить
Anonymous
 Борьба с мульти оси

Сообщение Anonymous »

Я застрял с частью моего кода, который обрабатывает вращение игрового субъекта. axis.
When horizontal input is detected the subject gets moved and rotated with following logic:

[*]If is the first horizontal Input of the game, or is in the same direction of the last one ( laStoRizontalInput ) субъект просто движется в направлении ввода, и его вращение выравнивается с направлением движения (наклон);
[*] if фактический горизонтальный вход находится в противоположном направлении последнего lasthorsond honspond hystruispond hourspont hold struispond hourspond hystruizond hoursport hourspond hystry stront hystry stront hystry strongy strongy strongy strongy strongy strongy. Поворот на 180 ° (на оси x) подробнее: если горизонтальный вход приносит субъект влево мы выполняем вращение по часовой стрелке , в противном случае, если двигаться в right направление против часовой часы ;
[*] , когда вращается, это не может быть, что не наступает, не должно быть, но не будет окончательно, но не будет окончательно, но не будет окончание, но не будет окончание, но не будет окончание, но не будет окончательно, но не будет окончание, но не будет окончательно, но не будет окончательно, но не будет окончательно, но не будет окончание. Затем, если есть вход, противоположный последнему старту, еще один флип (переменная Isturning );
[*] вращение 180 ° (поворот) корректируется (с TurnAddjustment переменная), рассматривая начальный угол , чтобы сделать все возможное, несмотря на все, что может быть в полном обороте, несмотря ни на начало, не может быть в полном повороте, несмотря на начало, что может быть сильным, может быть в полном повороте, несмотря на то, что он может быть сильным, может быть в полном обороте, несмотря на начало, что может быть наступает в полном повороте Поворот вдоль оси x происходит, когда закончено, что корабль сбрасывает его положение вдоль оси x (вращение спины). < /p>
< /li>
Некоторые вращения приводят к вращению корабля вдоль оси Y в противоположном направлении, поскольку он фактически должен (ES. от 330 ° до 0 ° до 360 ° ° < /P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> PreAedEase). /> < /li>
< /ol>
Позвольте мне специфить, что наклоны идеальны и работают прекрасно. И, несмотря на все обходной путь, который я пробовал (es. Row 579-580) не может преодолеть его. < /P>
Я думаю, что вызывает проблему сброса Y вращение во время хода, и текущая обработка покротации. < /P>
может кто-нибудь, чтобы помочь мне с этим? FixedUpdate: < /p>
if (horizontalInput != 0)
{
if (lateralTimer < 2f) lateralTimer += Time.deltaTime * gameSpeed;
lateralSpeed = standardLateralSpeed + (increaseValue / 5f) * standardLateralSpeed;
transform.position += new Vector3(0, 0, horizontalInput * Time.deltaTime * lateralSpeed * gameSpeed);

paragone = horizontalInput > 0 ? lastHorizontalInput < 0 : lastHorizontalInput > 0;
turnSide = lastHorizontalInput < 0 ? clockwiseTurn : counterclockwiseTurn;
tiltSide = lastHorizontalInput > 0 ? clockwiseTilt : counterclockwiseTilt;

if (paragone && !isTurning)
{
if (lastHorizontalInput > 0) turnAdjustment = transform.rotation.eulerAngles.x > 180f ? 360f - transform.rotation.eulerAngles.x : -transform.rotation.eulerAngles.x;
else turnAdjustment = transform.rotation.eulerAngles.x > 180f ? transform.rotation.eulerAngles.x - 360f : transform.rotation.eulerAngles.x;

Debug.Log($"[HI != 0][paragone = {paragone} && isTurning = {isTurning}] PRE COROUTINE -> Actual currentXRotation: {currentXRotation} | cw Tilt: {clockwiseTilt} | ccw Tilt: {counterclockwiseTilt} | turnAdjustment: {turnAdjustment}");
StartCoroutine(TurnRotation(turnSide.x, transform.rotation.eulerAngles));
Debug.Log($"[HI != 0][paragone = {paragone} && isTurning = {isTurning}] POST COROUTINE -> Actual currentXRotation: {currentXRotation} | cw Tilt: {clockwiseTilt} | ccw Tilt: {counterclockwiseTilt}");
lastHorizontalInput = (int)Mathf.Sign(horizontalInput);
}
else
{
if (isTurning)
{
turnReducer = currentXRotation - tiltSide.x;
Debug.Log($"[HI != 0][paragone = {paragone}][isTurning = {isTurning}][ELSE][IF] IN TURN, turnReducer: {turnReducer}");
}
else
{
lastHorizontalInput = (int)Mathf.Sign(horizontalInput);
Debug.Log($"[HI != 0 | HI = {horizontalInput}][paragone = {paragone}][isTurning = {isTurning}][ELSE][ELSE] TILT ");
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(tiltSide), rotationLerpRate * Time.deltaTime * gameSpeed);
}
}
}
else
{
if (lateralSpeed > 0)
{
turnReducer = 0f;
lateralSpeedRadianti = Mathf.Deg2Rad * (lateralSpeed * (90f / standardLateralSpeed));
lateralSpeed -= lateralSpeed - (lateralDecelerationRate + lateralDecelerationRate * Mathf.Cos(lateralSpeedRadianti)) > 0 ? lateralDecelerationRate + lateralDecelerationRate * Mathf.Cos(lateralSpeedRadianti) : lateralSpeed;
lateralReducer = lateralTimer > 0.25f ? 2f / (lateralTimer / 2f) : 8f;
transform.position += new Vector3(0, 0, lastHorizontalInput * Time.deltaTime * (lateralSpeed / lateralReducer) * gameSpeed);
Debug.Log($"[HI == 0][LS > 0] Movimento effettuato");

if (!isTurning)
{
settlingAngleFactor = 3f / lateralTimer;
settlingSpeedFactor = rotationLerpRate * (1f + lateralTimer / 2f);

settlingXAmount = lastHorizontalInput > 0 ? currentXRotation - (35f / settlingAngleFactor) : currentXRotation + (35f / settlingAngleFactor);
settlingYAmount = lastHorizontalInput > 0 ? 25f / settlingAngleFactor : -25f / settlingAngleFactor;

settlingReducedTilt = new Vector3(settlingXAmount, settlingYAmount, 10f * acceleRatio * NoseUpNoseDown);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(settlingReducedTilt), settlingSpeedFactor * Time.deltaTime * gameSpeed);

Debug.Log($"[HI == 0 | LHI = {lastHorizontalInput}][LS > 0][isTurning={isTurning}] Assestamento effettuato: {transform.rotation.eulerAngles} | settlingReducedTilt: {settlingReducedTilt} | rotazione: {transform.rotation.eulerAngles}");
}
}
else
{
if (lateralSpeed != 0) lateralSpeed = 0;
if (lateralTimer != 0) lateralTimer = 0;
if (!isTurning) transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(standardAngle), rotationLerpRate * Time.deltaTime * gameSpeed);
Debug.Log($"[HI == 0][LS == 0] Stabilizzazione effettuato");
}
}
< /code>
И это метод обезвреживания: < /p>
private IEnumerator TurnRotation(float targetRotation, Vector3 startRotation)
{
float direction = Mathf.Sign(targetRotation);
float amountToRotate = 180f + turnAdjustment;
float baseRotationSpeed = 60f;
float dynamicRotationSpeed = 80f;
float rotationSpeed;
float TargetNoseUpNoseDown = -NoseUpNoseDown; // Sempre una rotazione di 180 gradi
float reducedAmountToRotate = amountToRotate - Mathf.Abs(turnReducer);
float startYRotation = startRotation.y;
float amountRotated = 0f;
float smoother = 0f;

isTurning = true;

if (startYRotation > 120f && startYRotation < 240f) startYRotation = startYRotation - 180f;
else if (startYRotation > 300f || startYRotation < 60f) startYRotation = startYRotation < 60f ? startYRotation : startYRotation - 360f;

Debug.Log($"[PRE WHILE] current X rotation: {currentXRotation} | standard angle: {standardAngle} | cw Tilt: {clockwiseTilt} | ccw Tilt: {counterclockwiseTilt} | Actual Rotation coord.: X:[{transform.rotation.eulerAngles}] | targetRotation: {targetRotation} | startRotation: {startRotation} | turnAdjustment: {turnAdjustment} | AmountToRotate: {amountToRotate} -> reducedAmountToRotate: {reducedAmountToRotate}");
while (amountRotated < reducedAmountToRotate)
{
reducedAmountToRotate = amountToRotate - Mathf.Abs(turnReducer);

// Calcola la rotazione Y
float progress = amountRotated / reducedAmountToRotate;
float yRotationThisFrame = Mathf.Lerp(startYRotation, 0, progress);
NoseUpNoseDown = Mathf.Lerp(-TargetNoseUpNoseDown, TargetNoseUpNoseDown, progress);

rotationSpeed = baseRotationSpeed + dynamicRotationSpeed * acceleRatio;
float rotationThisFrame = rotationSpeed * Time.deltaTime * gameSpeed;
smoother = (3.5f * rotationThisFrame) * Mathf.Sin(progress * (reducedAmountToRotate * Mathf.Deg2Rad));
Debug.Log($"[ROTATING: {amountRotated} of {reducedAmountToRotate}] current X rotation: {currentXRotation} | standard angle: {standardAngle} | cw Tilt: {clockwiseTilt} | ccw Tilt: {counterclockwiseTilt} | Actual Rotation coord.: X:[{transform.rotation.eulerAngles}] | yRotationThisFrame: {yRotationThisFrame} | startYRotation: {startYRotation}");
rotationThisFrame = Mathf.Min(rotationThisFrame + smoother, reducedAmountToRotate - amountRotated);
amountRotated += rotationThisFrame;

// Applica le rotazioni
transform.rotation = Quaternion.Euler(currentXRotation + (direction * amountRotated), yRotationThisFrame, standardAngle.z);
yield return null;
}

NoseUpNoseDown = TargetNoseUpNoseDown;
currentXRotation = (currentXRotation == 0) ? 180 : 0;
Debug.Log($"[POST WHILE] nose Up nose Down: {NoseUpNoseDown} | current X rotation: {currentXRotation} | standard angle: {standardAngle} | cw Tilt: {clockwiseTilt} | ccw Tilt: {counterclockwiseTilt} | Actual Rotation coord.: X:[{transform.rotation.eulerAngles.x}] - Y:[{transform.rotation.eulerAngles.y}] -Z:[{transform.rotation.eulerAngles.z}] ");

turnReducer = 0f;
turnAdjustment = 0f;
isTurning = false;
}


Подробнее здесь: https://stackoverflow.com/questions/796 ... n-struggle
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»