fix: improve Ship

This commit is contained in:
Théo LUDWIG 2025-05-17 20:28:15 +02:00
parent 699ba78ae4
commit becd9c455e
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
4 changed files with 2092 additions and 2086 deletions

File diff suppressed because it is too large Load Diff

View File

@ -7,9 +7,9 @@ public class ShipGameMode : IGameMode
private const float HorizontalSpeed = 8.6f; private const float HorizontalSpeed = 8.6f;
private const float JumpForce = 26.6581f; private const float JumpForce = 26.6581f;
private const KeyCode JumpKey = KeyCode.Space; private const KeyCode JumpKey = KeyCode.Space;
private const float UpperAngle = 45f; private const float MaxAscentAngle = 45f;
private const float LowerAngle = -45f; private const float MaxDescentAngle = -45f;
private const float RotationTransitionDuration = 0.5f; private const float RotationSpeed = 360f;
public void Update(Player player) public void Update(Player player)
{ {
@ -20,26 +20,28 @@ public class ShipGameMode : IGameMode
if (jumpPressed) if (jumpPressed)
{ {
Jump(player); Jump(player);
}
if (Input.GetKeyDown(JumpKey)) float targetAngle;
{ if (player.RigidBody.linearVelocity.y > 0.1f)
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle); {
} float velocityLerp = Mathf.Clamp01(player.RigidBody.linearVelocity.y / JumpForce);
else targetAngle = Mathf.Lerp(0f, MaxAscentAngle, velocityLerp);
{ }
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle); else if (player.RigidBody.linearVelocity.y < -0.1f)
} {
float velocityLerp = Mathf.Clamp01(Mathf.Abs(player.RigidBody.linearVelocity.y) / 20f);
targetAngle = Mathf.Lerp(0f, MaxDescentAngle, velocityLerp);
} }
else else
{ {
float currentAngle = GetCurrentZAngle(player); targetAngle = 0f;
float t = Mathf.Clamp01(Time.deltaTime / RotationTransitionDuration);
float interpolationFactor = Mathf.Sin(t * (Mathf.PI / 2));
float newAngle = Mathf.Lerp(currentAngle, LowerAngle, interpolationFactor);
player.Transform.rotation = Quaternion.Euler(0, 0, newAngle);
} }
float currentAngle = GetCurrentZAngle(player);
float newAngle = Mathf.MoveTowardsAngle(currentAngle, targetAngle, RotationSpeed * Time.deltaTime);
player.Transform.rotation = Quaternion.Euler(0, 0, newAngle);
if (player.Particle.gameObject.activeSelf) if (player.Particle.gameObject.activeSelf)
{ {
player.Particle.gameObject.SetActive(false); player.Particle.gameObject.SetActive(false);
@ -58,19 +60,21 @@ public class ShipGameMode : IGameMode
public void Jump(Player player) public void Jump(Player player)
{ {
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0); if (player.RigidBody.linearVelocity.y <= 0.1f)
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
if (player.LevelsLoader != null)
{ {
player.LevelsLoader.IncreaseTotalJumps(); player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
if (player.LevelsLoader != null)
{
player.LevelsLoader.IncreaseTotalJumps();
}
} }
} }
public void OnCollisionEnter(Player player, Collision2D collision) public void OnCollisionEnter(Player player, Collision2D collision)
{ {
float currentAngle = GetCurrentZAngle(player); float snappedAngle = 0f;
float shortestAngle = Mathf.DeltaAngle(currentAngle, 0); player.Transform.rotation = Quaternion.Euler(0, 0, snappedAngle);
player.Transform.rotation = Quaternion.RotateTowards(player.Transform.rotation, Quaternion.Euler(0, 0, 0), Mathf.Abs(shortestAngle));
} }
public void OnCollisionExit(Player player, Collision2D collision) public void OnCollisionExit(Player player, Collision2D collision)

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

View File

@ -49,3 +49,5 @@ cd cnam-geometry-dash
![Gameplay](./Documentation/Screenshots/gameplay.png) ![Gameplay](./Documentation/Screenshots/gameplay.png)
![Levels selection](./Documentation/Screenshots/levels-selection.png) ![Levels selection](./Documentation/Screenshots/levels-selection.png)
![Edit Level](./Documentation/Screenshots/edit-level.png)