Hello,
I’m making a game where you control a cube as it goes through a line of obstacles on it’s way. It would be in 3D and the obstacles are other cubes popping out of the wall and would kinda have a racing feel to it. Now, I need to know how to make a 3rd person controller for a cube so that it only can move up, down, left, and right. It would not have any gravity yet not constantly having it keep moving after you press the button. Also, the controls would be W A S D. Thanks for any help.
if you dont need any physics-based movement you could just use transform.position. That may cause some problems with collision though.
You could also use a rigidbody, set Use Gravity to false, make force applied only when the velocity is below the max speed (to limit speed), and then when the player is not pressing a button set the rigidbody’s velocity to 0 so it doesn’t keep moving when the button is no longer pressed with rigidbody.velocity = Vector3.zero.
I would recommend something like this, it uses a character controller and it goes in your Update()
function:
CharacterController Controller = GetComponent<CharacterController>();
Vector3 dir = thisTransform.forward * curSpeed;
if(Input.GetKey(KeyCode.W) && curSpeed < HighSpeed)
curSpeed += Input.GetAxis("Vertical") * Acceleration * Time.deltaTime;
if(Input.GetKey(KeyCode.S) && curSpeed > LowSpeed)
curSpeed -= Input.GetAxis("Vertical") * Acceleration * Time.deltaTime;
if(!Controller.isGrounded)
dir.y -= Gravity * Time.deltaTime;
Controller.Move(dir * Time.smoothDeltaTime);
You will need to define curSpeed, Gravity, HighSpeed, LowSpeed, Acceleration, and you may want to put set the Controller in the Start()
function.