C# Multi -Achse -RotationskampfC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 C# Multi -Achse -Rotationskampf

Post by Anonymous »

Ich stecke mit einem Stück meines Codes fest, der die Drehung des Spiels des Spiels behandelt. 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 ( Lasthorizontalinput ) Das Subjekt bewegt sich einfach in Richtung Eingangsrichtung, und es ist eine Drehung mit der beweglichen Richtung (Neigung); 180 ° drehen (auf der x -Achse) im Detail: Wenn die horizontale Eingabe das Subjekt links verleiht, führen wir eine im Uhrzeigersinnsrtatation , ansonsten, wenn Sie sich in der rechten Richtung gegen den Uhrzeigersinn bewegen, wenn die Drehung nicht galt. Wenn dann einen Eingang gegenüber dem letzten gibt, starten Sie einen weiteren Flip (variable -Anturning ); mehr oder weniger als 180 ° , abhängig von der Startrotation . Kippt , um die 180 ° -Drotation reibungslos in den Neigungswinkel ohne Gurte zu führen. Dies wird mit der -Verdrehwirtschaft erreicht. Um die Nase auch nach einer Drehung, die die Nase nach oben zeigte, nach oben zu halten (die 180 ° -Wendung), wurde die Naseupnosedown Variable erzeugt, um die Nasenrotation (die Drehung entlang der Z -Achse entlang der Z -Achse) einzustellen. Eingestellt in der Turnrotationsmethode zusammen mit der X -Rotation während der Kurve. Eingestellt in der Turnrotationsmethode zusammen mit den X & Z -Rotationen während der Kurve. Die beschriebenen Mechanik sind zwischen den Zeilen 235 bis 302 und in Zeile 564 für die Drehrotationsmethode. /> Drehung entlang der x -Achse tritt auf, wenn das Schiff zurückgesetzt wird, ist die Position entlang der x -Achse (rotierend zurück). /> < /li>
< /ol>
Lassen Sie mich spezifizieren, dass die Neigungen perfekt sind und vollkommen gut funktionieren. Und trotz aller Problemumgehungen, die ich ausprobiert habe (es. Zeile 579-580) kann nicht darüber hinwegkommen. FixedUpdate: < /p>

Code: Select all

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>
Und dies ist die Turnrotationsmethode: < /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;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post