Created
January 9, 2020 17:04
-
-
Save MrCl0wnLab/ccc11b23ea53dd27fad2a816ab0cfc35 to your computer and use it in GitHub Desktop.
Script movimentação de personagem Unity3D
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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Movimentacao : MonoBehaviour | |
{ | |
public Rigidbody rb; | |
public Animator anim; | |
public float moveSpeed = 20.0f; | |
Vector3 movement; | |
void Update() | |
{ | |
float xAxis = Input.GetAxisRaw("Horizontal"); | |
float zAxis = Input.GetAxisRaw("Vertical"); | |
movement = new Vector3(xAxis,0,zAxis) * moveSpeed * Time.deltaTime; | |
rb.MovePosition(transform.position + movement); | |
if(movement.x !=0 || movement.z !=0){ | |
anim.SetBool("Run", true); | |
}else{ | |
anim.SetBool("Run", false); | |
} | |
if(xAxis == 1){ | |
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.Euler(0,90,0) , moveSpeed); | |
} | |
if(xAxis == -1){ | |
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.Euler(0,-90,0) , Time.deltaTime * moveSpeed); | |
} | |
if(zAxis == 1){ | |
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.Euler(0,0,0), Time.deltaTime * moveSpeed); | |
} | |
if(zAxis == -1){ | |
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.Euler(0,-180,0), Time.deltaTime * moveSpeed); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment