Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c04f3d802 | ||
|
|
a0d01964c7 | ||
|
|
b696d526d5 | ||
|
|
b6ad41aa53 | ||
|
|
d50f3f315e | ||
|
|
e99156177b | ||
|
|
8c48b3bdbb | ||
|
|
8891b70641 | ||
|
|
d8e0b5fa80 | ||
|
|
71667543b7 | ||
|
|
e104e71bba | ||
|
|
bb50976229 | ||
|
|
a38633b581 |
@@ -147,8 +147,8 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 150911451}
|
m_GameObject: {fileID: 150911451}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0.5, z: 0.5}
|
m_LocalPosition: {x: 0, y: 0.5, z: 0}
|
||||||
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
|
m_LocalScale: {x: 0.25, y: 0.5, z: 1.5}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 741217456}
|
m_Father: {fileID: 741217456}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
@@ -538,6 +538,9 @@ MonoBehaviour:
|
|||||||
speed: 20
|
speed: 20
|
||||||
jumpSpeed: 20
|
jumpSpeed: 20
|
||||||
gravity: 5
|
gravity: 5
|
||||||
|
rotationSpeed: 20
|
||||||
|
pivot: {fileID: 1402695046}
|
||||||
|
playerModel: {fileID: 150911451}
|
||||||
--- !u!143 &741217458
|
--- !u!143 &741217458
|
||||||
CharacterController:
|
CharacterController:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class CameraController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
pivot.position = player.position;
|
pivot.position = player.position;
|
||||||
pivot.parent = player.transform;
|
pivot.parent = null;
|
||||||
|
|
||||||
Cursor.visible = !Cursor.visible;
|
Cursor.visible = !Cursor.visible;
|
||||||
Cursor.lockState = CursorLockMode.Locked;
|
Cursor.lockState = CursorLockMode.Locked;
|
||||||
@@ -27,7 +27,7 @@ public class CameraController : MonoBehaviour
|
|||||||
|
|
||||||
void LateUpdate(){
|
void LateUpdate(){
|
||||||
float camX = Input.GetAxisRaw("Mouse X") * rotateSpeed;
|
float camX = Input.GetAxisRaw("Mouse X") * rotateSpeed;
|
||||||
player.Rotate(0, camX, 0);
|
pivot.Rotate(0, camX, 0);
|
||||||
|
|
||||||
float camY = Input.GetAxisRaw("Mouse Y") * rotateSpeed;
|
float camY = Input.GetAxisRaw("Mouse Y") * rotateSpeed;
|
||||||
if (invertY){
|
if (invertY){
|
||||||
@@ -36,6 +36,12 @@ public class CameraController : MonoBehaviour
|
|||||||
pivot.Rotate(-camY, 0, 0);
|
pivot.Rotate(-camY, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Input.GetKey(KeyCode.LeftShift))
|
||||||
|
{
|
||||||
|
player.Rotate(0, camX, 0);
|
||||||
|
pivot.Rotate(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if(pivot.rotation.eulerAngles.x > maxViewAngle && pivot.rotation.eulerAngles.x < 180f)
|
if(pivot.rotation.eulerAngles.x > maxViewAngle && pivot.rotation.eulerAngles.x < 180f)
|
||||||
{
|
{
|
||||||
pivot.rotation = Quaternion.Euler(maxViewAngle, 0, 0);
|
pivot.rotation = Quaternion.Euler(maxViewAngle, 0, 0);
|
||||||
@@ -47,18 +53,21 @@ public class CameraController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
float camZ = Input.GetAxisRaw("Mouse ScrollWheel");
|
float camZ = Input.GetAxisRaw("Mouse ScrollWheel");
|
||||||
|
float angleY = pivot.eulerAngles.y;
|
||||||
float angleX = pivot.eulerAngles.x;
|
float angleX = pivot.eulerAngles.x;
|
||||||
float angleY = player.eulerAngles.y;
|
|
||||||
float cameraAngle = transform.eulerAngles.y;
|
|
||||||
|
|
||||||
//if (Mathf.Abs(cameraAngle - angleY) <= 45){ Potential start for camera following similar to banjo/mario64
|
/* Code to force the camera behind the player
|
||||||
|
if(Input.GetKey(KeyCode.LeftShift))
|
||||||
|
{
|
||||||
|
angleY = player.eulerAngles.y;
|
||||||
|
angleX = player.eulerAngles.x;
|
||||||
|
} */
|
||||||
|
|
||||||
|
float cameraAngle = transform.eulerAngles.y;
|
||||||
|
|
||||||
Quaternion rotation = Quaternion.Euler(angleX, angleY, 0);
|
Quaternion rotation = Quaternion.Euler(angleX, angleY, 0);
|
||||||
transform.position = player.position - (rotation * offset);
|
transform.position = player.position - (rotation * offset);
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
if(transform.position.y < player.position.y){
|
if(transform.position.y < player.position.y){
|
||||||
transform.position = new Vector3(transform.position.x, player.position.y - 0.5f, transform.position.z);
|
transform.position = new Vector3(transform.position.x, player.position.y - 0.5f, transform.position.z);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ public class PlayerController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
CharacterController characterController;
|
CharacterController characterController;
|
||||||
|
|
||||||
public float speed = 20.0f;
|
public float speed;
|
||||||
public float jumpSpeed = 15.0f;
|
public float jumpSpeed;
|
||||||
public float gravity = 5.0f;
|
public float gravity;
|
||||||
public float rotationSpeed = 150.0f;
|
public float rotationSpeed;
|
||||||
|
public Transform pivot;
|
||||||
|
public GameObject playerModel;
|
||||||
|
|
||||||
private bool extraJump = true;
|
private bool extraJump = true;
|
||||||
private Vector3 moveDirection;
|
private Vector3 moveDirection;
|
||||||
@@ -28,10 +30,8 @@ public class PlayerController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
|
|
||||||
float yStore = moveDirection.y;
|
float yStore = moveDirection.y;
|
||||||
moveDirection = (transform.forward * Input.GetAxisRaw("Vertical")) + (transform.right * Input.GetAxisRaw("Horizontal"));
|
//Need to switch to 'raw' when using keyboard
|
||||||
|
moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
|
||||||
//Player rotation
|
|
||||||
transform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * rotationSpeed, 0);
|
|
||||||
|
|
||||||
if (extraJump == true)
|
if (extraJump == true)
|
||||||
{
|
{
|
||||||
@@ -73,5 +73,15 @@ public class PlayerController : MonoBehaviour
|
|||||||
|
|
||||||
// Move the controller
|
// Move the controller
|
||||||
characterController.Move(moveDirection * Time.deltaTime);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
m_EditorVersion: 2019.2.8f1
|
m_EditorVersion: 2019.2.11f1
|
||||||
m_EditorVersionWithRevision: 2019.2.8f1 (ff5b465c8d13)
|
m_EditorVersionWithRevision: 2019.2.11f1 (5f859a4cfee5)
|
||||||
|
|||||||
Reference in New Issue
Block a user