- Home /
Question by
unity_W5rSjPGNxUhHXA · Jun 23, 2019 at 10:21 PM ·
c#physicscharactercontroller
How can I add Character Controller to my script?
Hi, I just wanted to know how to add a CharacterController.move to this script on my player. Thanks in advance:
public float speed = 10;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (anim == null) return;
var x = Input.GetAxis("Horizontal");
var y = Input.GetAxis("Vertical");
Move(x, y);
}
private void Move(float x, float y)
{
anim.SetFloat("VelX", x);
anim.SetFloat("VelY", y);
Vector3 playerMovement = new Vector3(x, 0f, y) * speed * Time.deltaTime;
transform.Translate(playerMovement, Space.Self);
if (Input.GetMouseButtonDown(0))
{
anim.SetTrigger("playerHit");
}
}
}
Comment