Search Unity

Change the rotation of RigidbodyFPController when gravity changed. Please Help!!

Discussion in 'Physics' started by Red_Kay, May 8, 2017.

  1. Red_Kay

    Red_Kay

    Joined:
    Aug 14, 2015
    Posts:
    94
    Yo!

    So I am making a FPS game where player can control its gravity. The Physics.gravity is set to 0 as I want other objects in the scene floating. I am simulating gravity on player by AddForce function. Gravity can be changed in any direction, I am stuck on, when player changes the gravity to be in negative x-axis the player rotates so that its bottom is facing in the direction of gravity(done using animation), the movement of the player gets messy and in-controllable.
    I am using the Rigidbody First person Controller prefab of Standard Assets with some minor modifications.

    I found these lines in the RBFPController script:

    Code (CSharp):
    1.                 Vector3 desiredMove = cam.transform.forward*input.y + cam.transform.right*input.x;
    2.  
    3.                 desiredMove = Vector3.ProjectOnPlane(desiredMove, m_GroundContactNormal).normalized;
    4.  
    5.                 desiredMove.x = desiredMove.x*movementSettings.CurrentTargetSpeed;
    6.                 desiredMove.z = desiredMove.z*movementSettings.CurrentTargetSpeed;
    7.                 desiredMove.y = desiredMove.y*movementSettings.CurrentTargetSpeed;
    8.                 if (m_RigidBody.velocity.sqrMagnitude <
    9.                     (movementSettings.CurrentTargetSpeed*movementSettings.CurrentTargetSpeed))
    10.                 {
    11.                     m_RigidBody.AddForce(desiredMove*SlopeMultiplier(), ForceMode.Impulse);
    12.                 }
    Watch the video!


    **When I change the gravity to be in -x axis the "Player" rotates and falls, controls go wrong**
     
    Last edited: May 8, 2017
  2. philliptemdayo

    philliptemdayo

    Joined:
    Jan 11, 2017
    Posts:
    1
    i think you should make the rigidbody static. Then rotate the camera via code instead of using animation. (i think so, not sure, but that is what i would do instead)