Compare commits

...
3 changed files with 25 additions and 12 deletions
+5 -2
View File
@@ -147,8 +147,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 150911451}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.5, z: 0.5}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_LocalPosition: {x: 0, y: 0.5, z: 0}
m_LocalScale: {x: 0.25, y: 0.5, z: 1.5}
m_Children: []
m_Father: {fileID: 741217456}
m_RootOrder: 0
@@ -538,6 +538,9 @@ MonoBehaviour:
speed: 20
jumpSpeed: 20
gravity: 5
rotationSpeed: 20
pivot: {fileID: 1402695046}
playerModel: {fileID: 150911451}
--- !u!143 &741217458
CharacterController:
m_ObjectHideFlags: 0
+18 -8
View File
@@ -11,10 +11,12 @@ public class PlayerController : MonoBehaviour
{
CharacterController characterController;
public float speed = 20.0f;
public float jumpSpeed = 15.0f;
public float gravity = 5.0f;
public float rotationSpeed = 150.0f;
public float speed;
public float jumpSpeed;
public float gravity;
public float rotationSpeed;
public Transform pivot;
public GameObject playerModel;
private bool extraJump = true;
private Vector3 moveDirection;
@@ -28,10 +30,8 @@ public class PlayerController : MonoBehaviour
{
float yStore = moveDirection.y;
moveDirection = (transform.forward * Input.GetAxisRaw("Vertical")) + (transform.right * Input.GetAxisRaw("Horizontal"));
//Player rotation
transform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * rotationSpeed, 0);
//Need to switch to 'raw' when using keyboard
moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
if (extraJump == true)
{
@@ -73,5 +73,15 @@ public class PlayerController : MonoBehaviour
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
//Move the player in different directions based on camera look direction
//Need to switch to 'raw' when using keyboard
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
{
transform.rotation = Quaternion.Euler(0f, pivot.rotation.eulerAngles.y, 0f);
Quaternion newRotation = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, newRotation, rotationSpeed * Time.deltaTime);
}
}
}
+2 -2
View File
@@ -1,2 +1,2 @@
m_EditorVersion: 2019.2.8f1
m_EditorVersionWithRevision: 2019.2.8f1 (ff5b465c8d13)
m_EditorVersion: 2019.2.11f1
m_EditorVersionWithRevision: 2019.2.11f1 (5f859a4cfee5)