Я застрял с частью моего кода, который обрабатывает вращение игрового субъекта. 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
Борьба с мульти оси ⇐ C#
Место общения программистов C#
1758607274
Anonymous
Я застрял с частью моего кода, который обрабатывает вращение игрового субъекта. axis.
When horizontal input is detected the subject gets moved and rotated with following logic:
[*][b]If[/b] is the [b]first horizontal Input[/b] of the game, or is in the [b]same direction[/b] of the [b]last one[/b] ([b] laStoRizontalInput [/b]) субъект просто движется в направлении ввода, и его вращение выравнивается с направлением движения (наклон);
[*] [b] if [/b] [b] фактический горизонтальный вход [/b] находится в [b] противоположном направлении последнего lasthorsond honspond hystruispond hourspont hold struispond hourspond hystruizond hoursport hourspond hystry stront hystry stront hystry strongy strongy strongy strongy strongy strongy. Поворот на 180 ° (на оси x) подробнее: если горизонтальный вход приносит субъект [b] влево [/b] мы выполняем вращение [b] по часовой стрелке [/b], в противном случае, если двигаться в [b] right [/b] направление [b] против часовой часы [/b];
[*] , когда вращается, это не может быть, что не наступает, не должно быть, но не будет окончательно, но не будет окончательно, но не будет окончание, но не будет окончание, но не будет окончание, но не будет окончательно, но не будет окончание, но не будет окончательно, но не будет окончательно, но не будет окончательно, но не будет окончание. Затем, если есть вход, противоположный последнему старту, еще один флип (переменная [b] Isturning [/b]);
[*] вращение [b] 180 ° (поворот) корректируется (с TurnAddjustment [/b] переменная), рассматривая начальный угол , чтобы сделать все возможное, несмотря на все, что может быть в полном обороте, несмотря ни на начало, не может быть в полном повороте, несмотря на начало, что может быть сильным, может быть в полном повороте, несмотря на то, что он может быть сильным, может быть в полном обороте, несмотря на начало, что может быть наступает в полном повороте Поворот вдоль оси 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;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79611076/multi-axis-rotation-struggle[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия