Closed #15 Character player movement
This commit is contained in:
parent
6f44edcd7b
commit
200ce10122
File diff suppressed because it is too large
Load Diff
@ -9,33 +9,58 @@ 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)
|
||||||
|
{
|
||||||
|
MoveCharacterPlayer();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveShipPlayer();
|
||||||
RotatePlayer();
|
RotatePlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#region Movement
|
#region Movement
|
||||||
|
|
||||||
public void OnMove(InputValue value)
|
public void OnMove(InputValue value)
|
||||||
@ -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;
|
||||||
@ -57,6 +82,14 @@ namespace _02.Scripts.WaterAndShip
|
|||||||
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
|
||||||
|
|
||||||
#region AssaultMode/DreadgeMode Switch
|
#region AssaultMode/DreadgeMode Switch
|
||||||
|
@ -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
|
||||||
|
@ -17,7 +17,7 @@ TagManager:
|
|||||||
- Water
|
- Water
|
||||||
- UI
|
- UI
|
||||||
-
|
-
|
||||||
-
|
- Ship
|
||||||
- Player
|
- Player
|
||||||
- Pirate
|
- Pirate
|
||||||
- Enemy
|
- Enemy
|
||||||
|
Loading…
Reference in New Issue
Block a user