Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- private var rotacao : float;
- private var distancia : float;
- private var xpos : float;
- private var zpos : float;
- public var player : GameObject;
- public var xcam : Camera;
- public var terreno : GameObject;
- private var grounded : boolean = false;
- @script RequireComponent(Rigidbody, CapsuleCollider)
- function Start() {
- distancia = 0.1;
- player.rigidbody.freezeRotation = true;
- player.rigidbody.useGravity = true;
- }
- function Update() {
- if(Input.GetKey(KeyCode.W)) {
- rotacao = xcam.transform.eulerAngles.y;
- xpos = (distancia * Mathf.Sin(rotacao*(Mathf.PI/180))) / 2.0;
- zpos = (distancia * Mathf.Cos(rotacao*(Mathf.PI/180))) / 2.0;
- player.transform.Translate(xpos,0,zpos);
- }
- else if(Input.GetKey(KeyCode.S)) {
- rotacao = xcam.transform.eulerAngles.y + 180.0;
- xpos = (distancia * Mathf.Sin(rotacao*(Mathf.PI/180))) / 2.0;
- zpos = (distancia * Mathf.Cos(rotacao*(Mathf.PI/180))) / 2.0;
- player.transform.Translate(xpos,0,zpos);
- }
- else if(Input.GetKey(KeyCode.A)) {
- rotacao = xcam.transform.eulerAngles.y - 90.0;
- xpos = (distancia * Mathf.Sin(rotacao*(Mathf.PI/180))) / 2.0;
- zpos = (distancia * Mathf.Cos(rotacao*(Mathf.PI/180))) / 2.0;
- player.transform.Translate(xpos,0,zpos);
- }
- else if(Input.GetKey(KeyCode.D)) {
- rotacao = xcam.transform.eulerAngles.y + 90.0;
- xpos = (distancia * Mathf.Sin(rotacao*(Mathf.PI/180))) / 2.0;
- zpos = (distancia * Mathf.Cos(rotacao*(Mathf.PI/180))) / 2.0;
- player.transform.Translate(xpos,0,zpos);
- }
- else if(Input.GetKey(KeyCode.Space)) {
- if(grounded == true) {
- player.transform.Translate(0.0,1.0,0.0);
- grounded = false;
- }
- }
- }
- function OnCollisionEnter (hit : Collision) {
- if(hit.gameObject.name == terreno.name) {
- grounded = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement