Player movement script

Hi everyone. I’ll be straight-forward here and ask if anyone can help me visualize a script for simple player movement? I’m trying to make a character walk on an arena with a static overhead camera. I don’t know whether to use transform, rigidbody, or character controller. I’ve been banging my head against a wall for 3 days now to write a script that meets my conditions. I’ve really been struggling with scripting, being new to Unity and Game Development in general. Plus, there’s a deadline I’ve got to meet. Can any of you folks help me? I promise I’ll learn the script and not just slap it into unity.

My conditions:
3d movement (forward, backward, left and right)
Rotates to the direction he is going to
checks if character is grounded

Any help will be of much appreciation. Thanks.

P.S. I uploaded a screenshot of the scene just to give you a visualization of what I meant.

Do you want to rotate towards a mouse cursor? or by controller analog or something?

Anyways here’s a start of the left/forward/back/right

public float speed = 5; // set speed
public float distancetoGround;



void Start()
{
distancetoGround = collider.bounds.extents.y;
}

void Update()
{

if (Input.GetKeyDown(KeyCode.UpArrow))
{
Vector3.forward * speed * time.deltatime
}

if (Input.GetKeyDown(KeyCode.DownArrow))
{
Vector3.back * speed * time.deltatime
}

if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Vector3.left * speed * time.deltatime
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
Vector3.Right * speed * time.deltatime
}

if (Input.GetKeyDown(KeyCode.Space)) && isGrounded())
{
 // do jump // assuming you want to check if you can jump
}

}


public bool isGrounded(bool checkGrounded)
{
return Physics.Raycast(transform.position,-Vector3.up, distToGround +0.1);}
}
1 Like

I’d like it to rotate as I press the buttons also. it would be like the character is always facing the direction he is going to. something like what a virtual joystick will achieve, seeing that I have one on the bottom left corner :slight_smile: