Merge pull request #8 from gjcampbell777/directional_rotation
Directional rotation
This commit is contained in:
@@ -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,7 +538,9 @@ MonoBehaviour:
|
|||||||
speed: 20
|
speed: 20
|
||||||
jumpSpeed: 20
|
jumpSpeed: 20
|
||||||
gravity: 5
|
gravity: 5
|
||||||
rotationSpeed: 200
|
rotationSpeed: 20
|
||||||
|
pivot: {fileID: 1402695046}
|
||||||
|
playerModel: {fileID: 150911451}
|
||||||
--- !u!143 &741217458
|
--- !u!143 &741217458
|
||||||
CharacterController:
|
CharacterController:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -30,9 +32,6 @@ public class PlayerController : MonoBehaviour
|
|||||||
float yStore = moveDirection.y;
|
float yStore = moveDirection.y;
|
||||||
moveDirection = (transform.forward * Input.GetAxisRaw("Vertical")) + (transform.right * Input.GetAxisRaw("Horizontal"));
|
moveDirection = (transform.forward * Input.GetAxisRaw("Vertical")) + (transform.right * Input.GetAxisRaw("Horizontal"));
|
||||||
|
|
||||||
//Player rotation
|
|
||||||
transform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * rotationSpeed, 0);
|
|
||||||
|
|
||||||
if (extraJump == true)
|
if (extraJump == true)
|
||||||
{
|
{
|
||||||
moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run
|
moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run
|
||||||
@@ -73,5 +72,14 @@ 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
|
||||||
|
if(Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user