Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Character keeps tiping forward using .AddForce and Capsule Collider

Discussion in 'Physics' started by TheFabiocool, Jun 6, 2015.

  1. TheFabiocool

    TheFabiocool

    Joined:
    Jun 4, 2015
    Posts:
    6
    Hello. I am fairly new to Unity, but I'm getting the hang of it so far! :D
    Thing is, I am not used to using PhyX and RigidBody movement, I've been trying to use only character controllers so far, but with good results! But as you can see from the title, I have this little problem.. Here is the script that I am using to try and make my character move:

    Code (CSharp):
    1. public float forwardForce = 1F;
    2.     Rigidbody rb;
    3.     ForceMode mode = ForceMode.Force;
    4.  
    5.     void Start () {
    6.         rb = GetComponent<Rigidbody>();
    7.     }
    8.  
    9.  
    10.     void FixedUpdate () {
    11.         float h = Input.GetAxis("Horizontal");
    12.         float v = Input.GetAxis ("Vertical");
    13.  
    14.  
    15.         if (Input.GetAxis ("Vertical") > 0) {
    16.             rb.AddForce(0f, 0f, 1f, mode );
    17.         }
    18.     }
    What happens is that my character tips forward... Any help? If you need any more info, please do tell me, and I will provide it.. I'm pretty sure all of this is just some bad programming of mine lol.
     
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    try constraining your characters rigidbodies rotations. Its on the bottom of the rigidbody component.
     
  3. TheFabiocool

    TheFabiocool

    Joined:
    Jun 4, 2015
    Posts:
    6
    I thought of this, but if I do so, will I be able to change those axis programmatically?
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I believe so.