[Solved]Changing from character controller to rigidbody

Updated on June 2, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on June 1, 2017

Where would I need to add force in this once character controller script please.


public float moveSpeed = 5;
public float moveSpeedSmooth = 0.3f;
public float rotateSpeedSmooth = 0.3f;
public float rotationSpeed = 180;

float moveSmoothUse;
float currentForwardSpeed;
float forwardSpeedV;

float targetRotation;
float currentRotation;
float rotationV;

Vector3 currentMovementV;

Rigidbody controller;
Vector3 currentMovement;
public Camera cameraTransform;
float verticalSpeed;

void Start ()
jumpAllowTimeTrack = jumpAllowTime;
moveSmoothUse = moveSpeedSmooth;
controller = GetComponent ();


void Update ()
if (PauseMenu.IsOn)

Vector3 horizontalInput = new Vector3 (Input.GetAxis (“Horizontal”), 0, Input.GetAxis (“Vertical”));
if (horizontalInput.magnitude > 1)
horizontalInput.Normalize ();

Vector3 targetHorizontalMovement = horizontalInput;
targetHorizontalMovement = cameraTransform.transform.TransformDirection (targetHorizontalMovement);
targetHorizontalMovement.y = 0;
targetHorizontalMovement.Normalize ();
targetHorizontalMovement *= horizontalInput.magnitude;

currentMovement = Vector3.SmoothDamp (currentMovement, targetHorizontalMovement * moveSpeed, ref currentMovementV, moveSmoothUse);

Quaternion targetRotatingQ = Quaternion.LookRotation (Vector3.forward);
if (new Vector3 (currentMovement.x, 0, currentMovement.z).magnitude > 1) {
targetRotatingQ = Quaternion.LookRotation (new Vector3 (currentMovement.x, 0, currentMovement.z));
transform.Rotate (0, Input.GetAxis (“Horizontal”) * rotationSpeed * Time.deltaTime, 0);

transform.rotation = Quaternion.Euler(0, Mathf.SmoothDampAngle(transform.rotation.eulerAngles.y, targetRotatingQ.eulerAngles.y, ref rotationV, rotateSpeedSmooth), 0);

  • Liked by
1 on June 1, 2017

I’m wondering if you wrote that script in the first place.

on June 2, 2017

No I didn’t and never claimed to. I’m learning and the way I learn is by following tutorials on youtube and then changing the scripts. I’ve only written a few things completely on my own. When I do add force, it doesn’t stop, so I’m trying to learn why.


You got a problem with people learning? What’s with the attitude anyway?

Show more replies
  • Liked by
1 on June 2, 2017

Solved, finally have my improved movement script. Gotta couple little tweeks to make, but w00t, that took awhile.

on June 2, 2017


controller.AddForce (transform.forward * Time.deltaTime , ForceMode.VelocityChange);


Just before Vector3 targetHorizontalMovement = horizontalInput;

Show more replies
  • Liked by