Closed #15 Character player movement

This commit is contained in:
M1_IDMhan 2023-08-15 17:29:24 +09:00
parent 6f44edcd7b
commit 200ce10122
4 changed files with 892 additions and 187 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9,31 +9,56 @@ namespace _02.Scripts.WaterAndShip
[RequireComponent(typeof(PlayerInput))] [RequireComponent(typeof(PlayerInput))]
public class Player : MonoBehaviour public class Player : MonoBehaviour
{ {
[Title("쉽의 기본 설정")] [Title("Component")]
[InfoBox("최대 스피드")]
public float maxSpeed = 10f;
[InfoBox("가속 수치")]
public float acceleration = 2f;
[InfoBox("감속 수치")]
public float deceleration = 2f;
[InfoBox("회전 속도")]
public float turnSpeed = 10f;
private Rigidbody rb; private Rigidbody rb;
private Vector2 movementInput; private Vector2 movementInput;
[Title("Child Object")]
private GameObject character;
[Title("쉽의 기본 설정")]
[Tooltip("최대 스피드")]
public float maxSpeed = 10f;
[Tooltip("가속 수치")]
public float acceleration = 2f;
[Tooltip("감속 수치")]
public float deceleration = 2f;
[Tooltip("회전 속도")]
public float turnSpeed = 10f;
[Title("캐릭터의 기본 설정")]
[Tooltip("캐릭터의 이동 속도")]
public float characterSpeed = 10f;
public bool IsAssaultMode { get; set; } public bool IsAssaultMode { get; set; }
public bool IsInShipMode { get; set; } public bool IsInShipMode { get; set; }
public bool IsdredgeMode { get; set; } public bool IsdredgeMode { get; set; }
private void Init()
{
character = transform.Find("Character").gameObject;
rb = GetComponent<Rigidbody>();
}
private void Awake() private void Awake()
{ {
rb = GetComponent<Rigidbody>(); Init();
} }
private void FixedUpdate() private void FixedUpdate()
{ {
MovePlayer(); if (IsInShipMode)
RotatePlayer(); {
MoveCharacterPlayer();
}
else
{
MoveShipPlayer();
RotatePlayer();
}
} }
#region Movement #region Movement
@ -43,7 +68,7 @@ namespace _02.Scripts.WaterAndShip
movementInput = value.Get<Vector2>(); movementInput = value.Get<Vector2>();
} }
private void MovePlayer() private void MoveShipPlayer()
{ {
var desiredVelocity = transform.forward * movementInput.y * maxSpeed; var desiredVelocity = transform.forward * movementInput.y * maxSpeed;
var speedChange = (movementInput.y != 0 ? acceleration : deceleration) * Time.fixedDeltaTime; var speedChange = (movementInput.y != 0 ? acceleration : deceleration) * Time.fixedDeltaTime;
@ -56,6 +81,14 @@ namespace _02.Scripts.WaterAndShip
var turnRotation = Quaternion.Euler(0f, turn * turnSpeed, 0f); var turnRotation = Quaternion.Euler(0f, turn * turnSpeed, 0f);
rb.MoveRotation(rb.rotation * turnRotation); rb.MoveRotation(rb.rotation * turnRotation);
} }
private void MoveCharacterPlayer()
{
Vector3 movement = character.transform.rotation *
new Vector3(-movementInput.y, 0, movementInput.x) * characterSpeed * Time.deltaTime;
character.transform.position += movement;
}
#endregion #endregion

View File

@ -18,7 +18,7 @@ PhysicsManager:
m_ClothInterCollisionDistance: 0.1 m_ClothInterCollisionDistance: 0.1
m_ClothInterCollisionStiffness: 0.2 m_ClothInterCollisionStiffness: 0.2
m_ContactsGeneration: 1 m_ContactsGeneration: 1
m_LayerCollisionMatrix: 100000001000000010000000381f00001f080000080000000000000000000000080700000807000008070000181000000808000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 m_LayerCollisionMatrix: 100000001000000010000000381f00001f080000080000000000000000010000880700000807000008070000181000000808000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
m_SimulationMode: 0 m_SimulationMode: 0
m_AutoSyncTransforms: 0 m_AutoSyncTransforms: 0
m_ReuseCollisionCallbacks: 0 m_ReuseCollisionCallbacks: 0

View File

@ -17,7 +17,7 @@ TagManager:
- Water - Water
- UI - UI
- -
- - Ship
- Player - Player
- Pirate - Pirate
- Enemy - Enemy