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,31 +9,56 @@ namespace _02.Scripts.WaterAndShip
|
||||
[RequireComponent(typeof(PlayerInput))]
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[Title("쉽의 기본 설정")]
|
||||
[InfoBox("최대 스피드")]
|
||||
public float maxSpeed = 10f;
|
||||
[InfoBox("가속 수치")]
|
||||
public float acceleration = 2f;
|
||||
[InfoBox("감속 수치")]
|
||||
public float deceleration = 2f;
|
||||
[InfoBox("회전 속도")]
|
||||
public float turnSpeed = 10f;
|
||||
|
||||
[Title("Component")]
|
||||
private Rigidbody rb;
|
||||
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 IsInShipMode { get; set; }
|
||||
public bool IsdredgeMode { get; set; }
|
||||
|
||||
private void Init()
|
||||
{
|
||||
character = transform.Find("Character").gameObject;
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
Init();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
MovePlayer();
|
||||
RotatePlayer();
|
||||
if (IsInShipMode)
|
||||
{
|
||||
MoveCharacterPlayer();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveShipPlayer();
|
||||
RotatePlayer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region Movement
|
||||
@ -43,7 +68,7 @@ namespace _02.Scripts.WaterAndShip
|
||||
movementInput = value.Get<Vector2>();
|
||||
}
|
||||
|
||||
private void MovePlayer()
|
||||
private void MoveShipPlayer()
|
||||
{
|
||||
var desiredVelocity = transform.forward * movementInput.y * maxSpeed;
|
||||
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);
|
||||
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
|
||||
|
||||
|
@ -18,7 +18,7 @@ PhysicsManager:
|
||||
m_ClothInterCollisionDistance: 0.1
|
||||
m_ClothInterCollisionStiffness: 0.2
|
||||
m_ContactsGeneration: 1
|
||||
m_LayerCollisionMatrix: 100000001000000010000000381f00001f080000080000000000000000000000080700000807000008070000181000000808000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
m_LayerCollisionMatrix: 100000001000000010000000381f00001f080000080000000000000000010000880700000807000008070000181000000808000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
m_SimulationMode: 0
|
||||
m_AutoSyncTransforms: 0
|
||||
m_ReuseCollisionCallbacks: 0
|
||||
|
@ -17,7 +17,7 @@ TagManager:
|
||||
- Water
|
||||
- UI
|
||||
-
|
||||
-
|
||||
- Ship
|
||||
- Player
|
||||
- Pirate
|
||||
- Enemy
|
||||
|
Loading…
Reference in New Issue
Block a user