Hi guys, Im looking for a good way to how set commands for a character control.
I.E.
down, forward and a button do something, or back, forward and a button
any idea how to code it?
thanks a lot
Hi guys, Im looking for a good way to how set commands for a character control.
I.E.
down, forward and a button do something, or back, forward and a button
any idea how to code it?
thanks a lot
void Update()
{
if (Input.GetKey(KeyCode.W))
{
Vector3 position = transform.position; // transform current position
Vector3 forward = transform.forward; // 3d direction the transform is looking at.
transform.position = position + forward * speed * Time.deltaTime; // moving forward
}
if (Input.GetKey(KeyCode.S))
{
Vector3 position = transform.position; // transform current position
Vector3 forward = transform.forward; // 3d direction the transform is looking at.
transform.position = position - forward * speed * Time.deltaTime; // moving backward
}
if (Input.GetKey(KeyCode.D))
{
Vector3 position = transform.position; // transform current position
Vector3 forward = transform.forward; // 3d direction the transform is looking at.
Vector3 right = new Vector3(forward.z, forward.y, -forward.x); // 2d clockwise perpendicular vector to (x, 0, z)
transform.position = position + right * speed * Time.deltaTime; // moving to the right
}
if (Input.GetKey(KeyCode.A))
{
Vector3 position = transform.position; // transform current position
Vector3 forward = transform.forward; // 3d direction the transform is looking at.
Vector3 right = new Vector3(forward.z, forward.y, -forward.x); // 2d clockwise perpendicular vector to (x, 0, z)
transform.position = position - right * speed * Time.deltaTime; // moving to the left
}
}
Some simple 2d movement on the xz plane.
This should get you started