Using Add Force for character control

Hi there I’ve been working on a game for a while now and recently realised how adding a force to my player character could be better than changing its transform.position for collisions however I am struggling to convert my old script to use AddForce.

Here is my script (you can see a commented line of how I tried to get the same effect but failed)

        //On Screen Controls
        direction = new Vector3(joyScript.position.x, 0, joyScript.position.y);
        if (direction.magnitude > 0.1f)
        {
            Vector3 rightMovement = right * ps3speed * Time.deltaTime * joyScript.position.x;
            Vector3 upMovement = forward * ps3speed * Time.deltaTime * joyScript.position.y;

            Vector3 heading = Vector3.Normalize(rightMovement + upMovement);
            transform.forward = heading;
            transform.position += rightMovement;
            transform.position += upMovement;
            //playerModel.rigidbody.AddForce(transform.forward * direction.magnitude);
            playerModel.animation.Play("runforward");
        }
        else
        {
            playerModel.animation.CrossFade("idle");
        }

If anyone could provide some assistance it would be much appreciated :slight_smile:
Thanks

I would expose the magnitude, or add another factor in that multiplication there and fiddle with it in the editor. Small enough values for AddForce will not make any difference.

So make this:

public float forceFactor;

and

playerModel.rigidbody.AddForce(forceFactor * transform.forward * direction.magnitude);