Compare commits

..
Author SHA1 Message Date
Gregory Campbell 4c04f3d802 Made character direction change more smooth and less binary 2019-11-17 20:17:16 -05:00
Gregory Campbell a0d01964c7 Merge branch 'directional_rotation' of github.com:gjcampbell777/3DSpeedPlatformer into directional_rotation 2019-11-10 21:06:21 -05:00
Gregory Campbell b696d526d5 Player moves based on where the camera is pointing and faces the direction in which it is moving 2019-11-10 21:04:52 -05:00
Gregory Campbell b6ad41aa53 Character faces direction but then input moves character relative to the position character is facing 2019-11-10 20:40:36 -05:00
Gregory CampbellandGitHub d50f3f315e Merge pull request #7 from gjcampbell777/free_rotating_camera
Free rotating camera
2019-11-10 20:39:26 -05:00
Gregory Campbell e99156177b Commented out the reset camera button since that functionality may be useless in the long run 2019-11-10 20:37:51 -05:00
Gregory Campbell 8c48b3bdbb Updated project version and scene 2019-11-10 19:33:17 -05:00
Gregory Campbell 8891b70641 Implemented static y axis rotation when reset button is pressed 2019-10-17 23:40:37 -04:00
Gregory Campbell d8e0b5fa80 Implemented free roam camera. Working on a button which resets camera location. 2019-10-13 14:02:58 -04:00
Gregory Campbell 71667543b7 Character faces direction but then input moves character relative to the position character is facing 2019-10-13 12:56:56 -04:00
Gregory Campbell e104e71bba Updated Unity Version 2019-10-13 12:30:41 -04:00
Gregory Campbell bb50976229 Inital push. Potential start to a camera that can 360 rotate around the player 2019-10-06 20:45:57 -04:00
Gregory CampbellandGitHub a38633b581 Merge pull request #6 from gjcampbell777/player_rotation
Added simple player rotation
2019-10-06 20:32:33 -04:00
4 changed files with 43 additions and 21 deletions
+5 -2
View File
@@ -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
+17 -8
View File
@@ -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);
} }
+18 -8
View File
@@ -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);
}
} }
} }
+2 -2
View File
@@ -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)