Created
July 26, 2016 13:11
-
-
Save arunkarnann/6d291944e0930fba4a21360bd8b70204 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[RequireComponent(typeof(CharacterController))] | |
public class GZThirdPersonSimplified : MonoBehaviour { | |
[SerializeField] float m_TurnSpeed = 20; | |
[SerializeField] float m_TurnAmount; | |
Vector3 RotationVector; | |
[SerializeField] Vector3 moveDirection = Vector3.zero; | |
public float speed = 6.0F; | |
public float jumpSpeed = 8.0F; | |
public float gravity = 20.0F; | |
void Update() { | |
CharacterController controller = GetComponent<CharacterController>(); | |
Debug.Log(this.gameObject.name+" "+controller.isGrounded); | |
if (controller.isGrounded) { | |
moveDirection = new Vector3(Input.GetAxis("Horizontal") , 0, Input.GetAxis("Vertical") ); | |
moveDirection = transform.TransformDirection(moveDirection); | |
RotationVector = moveDirection.x *Vector3.left + moveDirection.z*Vector3.forward; | |
if(moveDirection != Vector3.zero){ | |
moveDirection = transform.forward ; | |
} | |
//GetComponent<Animator>().SetBool("Walk",true); | |
moveDirection *= speed; | |
if (Input.GetButton("Jump")) | |
moveDirection.y = jumpSpeed; | |
} | |
moveDirection.y -= gravity * Time.deltaTime; | |
controller.Move(moveDirection * Time.deltaTime); | |
m_TurnAmount = Mathf.Atan2(RotationVector.x,RotationVector.z); | |
transform.Rotate(0, m_TurnAmount * m_TurnSpeed * Time.deltaTime, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment