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

View File

@ -2,7 +2,7 @@
"name": "StereoMadness", "name": "StereoMadness",
"musicName": "StereoMadness", "musicName": "StereoMadness",
"order": 0, "order": 0,
"difficulty": 1, "difficulty": 2,
"elements": [ "elements": [
{ {
"type": "ObstacleBlock", "type": "ObstacleBlock",

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,25 +20,27 @@ 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);
targetAngle = Mathf.Lerp(0f, MaxAscentAngle, velocityLerp);
}
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
{ {
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle); targetAngle = 0f;
} }
}
else
{
float currentAngle = GetCurrentZAngle(player); float currentAngle = GetCurrentZAngle(player);
float newAngle = Mathf.MoveTowardsAngle(currentAngle, targetAngle, RotationSpeed * Time.deltaTime);
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); player.Transform.rotation = Quaternion.Euler(0, 0, newAngle);
}
if (player.Particle.gameObject.activeSelf) if (player.Particle.gameObject.activeSelf)
{ {
@ -57,6 +59,8 @@ public class ShipGameMode : IGameMode
} }
public void Jump(Player player) public void Jump(Player player)
{
if (player.RigidBody.linearVelocity.y <= 0.1f)
{ {
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0); player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse); player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
@ -65,12 +69,12 @@ public class ShipGameMode : IGameMode
player.LevelsLoader.IncreaseTotalJumps(); 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)