mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-05-18 12:02:58 +02:00
fix: improve Ship
This commit is contained in:
parent
699ba78ae4
commit
becd9c455e
File diff suppressed because it is too large
Load Diff
@ -7,9 +7,9 @@ public class ShipGameMode : IGameMode
|
||||
private const float HorizontalSpeed = 8.6f;
|
||||
private const float JumpForce = 26.6581f;
|
||||
private const KeyCode JumpKey = KeyCode.Space;
|
||||
private const float UpperAngle = 45f;
|
||||
private const float LowerAngle = -45f;
|
||||
private const float RotationTransitionDuration = 0.5f;
|
||||
private const float MaxAscentAngle = 45f;
|
||||
private const float MaxDescentAngle = -45f;
|
||||
private const float RotationSpeed = 360f;
|
||||
|
||||
public void Update(Player player)
|
||||
{
|
||||
@ -20,26 +20,28 @@ public class ShipGameMode : IGameMode
|
||||
if (jumpPressed)
|
||||
{
|
||||
Jump(player);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(JumpKey))
|
||||
{
|
||||
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle);
|
||||
}
|
||||
float targetAngle;
|
||||
if (player.RigidBody.linearVelocity.y > 0.1f)
|
||||
{
|
||||
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
|
||||
{
|
||||
float currentAngle = GetCurrentZAngle(player);
|
||||
|
||||
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);
|
||||
targetAngle = 0f;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
player.Particle.gameObject.SetActive(false);
|
||||
@ -58,19 +60,21 @@ public class ShipGameMode : IGameMode
|
||||
|
||||
public void Jump(Player player)
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
|
||||
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
|
||||
if (player.LevelsLoader != null)
|
||||
if (player.RigidBody.linearVelocity.y <= 0.1f)
|
||||
{
|
||||
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)
|
||||
{
|
||||
float currentAngle = GetCurrentZAngle(player);
|
||||
float shortestAngle = Mathf.DeltaAngle(currentAngle, 0);
|
||||
player.Transform.rotation = Quaternion.RotateTowards(player.Transform.rotation, Quaternion.Euler(0, 0, 0), Mathf.Abs(shortestAngle));
|
||||
float snappedAngle = 0f;
|
||||
player.Transform.rotation = Quaternion.Euler(0, 0, snappedAngle);
|
||||
}
|
||||
|
||||
public void OnCollisionExit(Player player, Collision2D collision)
|
||||
|
BIN
Documentation/Screenshots/edit-level.png
Normal file
BIN
Documentation/Screenshots/edit-level.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 353 KiB |
Loading…
x
Reference in New Issue
Block a user