bugfix/fix-ship (#49)

Co-authored-by: Djelal BOUDJI <djelal@gmail.com>
This commit is contained in:
djelalb 2025-03-31 09:57:45 +02:00 committed by GitHub
parent d57cc647aa
commit aa6401f6bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 61 additions and 34 deletions

View File

@ -72,7 +72,7 @@ TextureImporter:
platformSettings: platformSettings:
- serializedVersion: 4 - serializedVersion: 4
buildTarget: DefaultTexturePlatform buildTarget: DefaultTexturePlatform
maxTextureSize: 2048 maxTextureSize: 1024
resizeAlgorithm: 0 resizeAlgorithm: 0
textureFormat: -1 textureFormat: -1
textureCompression: 1 textureCompression: 1

View File

@ -381,6 +381,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
playerObject: {fileID: 1267397455} playerObject: {fileID: 1267397455}
normalMinYFollow: 2
shipMinYFollow: 6
--- !u!1 &521952199 --- !u!1 &521952199
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -565,13 +567,13 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 725779773} m_GameObject: {fileID: 725779773}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: 0.96696675, w: 0.25490257} m_LocalRotation: {x: -0, y: -0, z: 0.9750753, w: 0.2218744}
m_LocalPosition: {x: 0.19, y: -0.64, z: -10} m_LocalPosition: {x: 0, y: -0.52, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 1267397458} m_Father: {fileID: 1267397458}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 150.464} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 154.362}
--- !u!199 &725779775 --- !u!199 &725779775
ParticleSystemRenderer: ParticleSystemRenderer:
serializedVersion: 6 serializedVersion: 6
@ -657,8 +659,8 @@ ParticleSystem:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 725779773} m_GameObject: {fileID: 725779773}
serializedVersion: 8 serializedVersion: 8
lengthInSec: 5 lengthInSec: 1
simulationSpeed: 1 simulationSpeed: 1.3
stopAction: 0 stopAction: 0
cullingMode: 0 cullingMode: 0
ringBufferMode: 0 ringBufferMode: 0
@ -732,7 +734,7 @@ ParticleSystem:
startLifetime: startLifetime:
serializedVersion: 2 serializedVersion: 2
minMaxState: 0 minMaxState: 0
scalar: 5 scalar: 0.5
minScalar: 5 minScalar: 5
maxCurve: maxCurve:
serializedVersion: 2 serializedVersion: 2
@ -785,7 +787,7 @@ ParticleSystem:
startSpeed: startSpeed:
serializedVersion: 2 serializedVersion: 2
minMaxState: 0 minMaxState: 0
scalar: 20 scalar: 5
minScalar: 5 minScalar: 5
maxCurve: maxCurve:
serializedVersion: 2 serializedVersion: 2
@ -872,8 +874,8 @@ ParticleSystem:
m_NumAlphaKeys: 2 m_NumAlphaKeys: 2
minGradient: minGradient:
serializedVersion: 2 serializedVersion: 2
key0: {r: 0.6528301, g: 0.6320044, b: 0.4865432, a: 1} key0: {r: 0.6906728, g: 0.81325835, b: 0.8415094, a: 1}
key1: {r: 0.82641506, g: 0.73513323, b: 0, a: 1} key1: {r: 0, g: 0.5758081, b: 0.827451, a: 1}
key2: {r: 0, g: 0, b: 0, a: 0} key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0} key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0} key4: {r: 0, g: 0, b: 0, a: 0}
@ -1280,15 +1282,15 @@ ParticleSystem:
ShapeModule: ShapeModule:
serializedVersion: 6 serializedVersion: 6
enabled: 1 enabled: 1
type: 4 type: 0
angle: 20 angle: 20
length: 5 length: 5
boxThickness: {x: 0, y: 0, z: 0} boxThickness: {x: 0, y: 0, z: 0}
radiusThickness: 1 radiusThickness: 0
donutRadius: 0.2 donutRadius: 0.2
m_Position: {x: 0, y: 0, z: 0} m_Position: {x: -0.000021252421, y: 0.000042931977, z: 0}
m_Rotation: {x: 0, y: 0, z: 0} m_Rotation: {x: -0, y: 0, z: 0.6191988}
m_Scale: {x: 1, y: 1, z: 1} m_Scale: {x: 0.99999994, y: 0.99999994, z: 1}
placementMode: 0 placementMode: 0
m_MeshMaterialIndex: 0 m_MeshMaterialIndex: 0
m_MeshNormalOffset: 0 m_MeshNormalOffset: 0
@ -1367,7 +1369,7 @@ ParticleSystem:
sphericalDirectionAmount: 0 sphericalDirectionAmount: 0
randomPositionAmount: 0 randomPositionAmount: 0
radius: radius:
value: 5 value: 1
mode: 0 mode: 0
spread: 0 spread: 0
speed: speed:

View File

@ -6,34 +6,51 @@ 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 UpperAngle = 45f;
private const float LowerAngle = -45f; private const float LowerAngle = -45f;
private const float RotationLerpSpeed = 5f; private const float RotationTransitionDuration = 0.5f;
public void Update(Player player) public void Update(Player player)
{ {
player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed, player.RigidBody.linearVelocity.y); player.RigidBody.linearVelocity = new Vector2(HorizontalSpeed, player.RigidBody.linearVelocity.y);
if (player.HasStarted && Input.GetKey(JumpKey)) bool jumpPressed = Input.GetKey(JumpKey);
if (player.HasStarted && jumpPressed)
{ {
Jump(player); Jump(player);
if (Input.GetKeyDown(JumpKey))
{
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle);
}
else
{
player.Transform.rotation = Quaternion.Euler(0, 0, UpperAngle);
}
}
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);
} }
float targetAngle = Input.GetKey(JumpKey) ? UpperAngle : LowerAngle; if (player.Particle.gameObject.activeSelf)
float currentAngle = player.Transform.rotation.eulerAngles.z; {
if (currentAngle > 180f) player.Particle.gameObject.SetActive(false);
currentAngle -= 360f; }
float newAngle = Mathf.Lerp(currentAngle, targetAngle, RotationLerpSpeed * Time.deltaTime);
player.Transform.rotation = Quaternion.Euler(0, 0, newAngle);
UpdateParticlePositionAndRotation(player);
} }
private void UpdateParticlePositionAndRotation(Player player) private float GetCurrentZAngle(Player player)
{ {
player.Particle.transform.position = player.Transform.position + new Vector3(-0.19f, -0.64f, -10); float angle = player.Transform.rotation.eulerAngles.z;
player.Particle.transform.rotation = Quaternion.Euler(0, 0, 150.464f); if (angle > 180f)
angle -= 360f;
return angle;
} }
private void Jump(Player player) private void Jump(Player player)
@ -56,7 +73,7 @@ public class ShipGameMode : IGameMode
return; return;
} }
float currentAngle = player.Transform.rotation.eulerAngles.z; float currentAngle = GetCurrentZAngle(player);
float shortestAngle = Mathf.DeltaAngle(currentAngle, 0); float shortestAngle = Mathf.DeltaAngle(currentAngle, 0);
player.Transform.rotation = Quaternion.RotateTowards(player.Transform.rotation, Quaternion.Euler(0, 0, 0), Mathf.Abs(shortestAngle)); player.Transform.rotation = Quaternion.RotateTowards(player.Transform.rotation, Quaternion.Euler(0, 0, 0), Mathf.Abs(shortestAngle));
} }

View File

@ -3,7 +3,8 @@ using UnityEngine;
public class PlayerCamera : MonoBehaviour public class PlayerCamera : MonoBehaviour
{ {
public GameObject playerObject; public GameObject playerObject;
public const float MIN_Y_FOLLOW = 2.0f; public float normalMinYFollow = 2.0f;
public float shipMinYFollow = 6.0f;
private float initialY; private float initialY;
private void Start() private void Start()
@ -13,9 +14,16 @@ public class PlayerCamera : MonoBehaviour
private void Update() private void Update()
{ {
float targetY = initialY; Player player = playerObject.GetComponent<Player>();
if (playerObject.transform.position.y > MIN_Y_FOLLOW) float minYFollow = normalMinYFollow;
if (player.CurrentGameMode is ShipGameMode)
{
minYFollow = shipMinYFollow;
}
float targetY = initialY;
if (playerObject.transform.position.y > minYFollow)
{ {
targetY = playerObject.transform.position.y; targetY = playerObject.transform.position.y;
} }