Search Unity

rigidbody FPS script help

Discussion in 'Scripting' started by morgansaysthis, Mar 25, 2007.

  1. morgansaysthis

    morgansaysthis

    Joined:
    Jan 12, 2007
    Posts:
    245
    hi im using the rigidbody FPS script joachim wrote here
    http://forum.unity3d.com/viewtopic.php?t=3222&highlight=rigidbody


    in the little game im making right now my char has to be able to be hit by moving walls,elevetors and moving obstacles rigidbody obstacles



    the probelm is He's going so fast around the level that he flies off little tiny bumbs in the terrain so hes just a little bit off the ground, which isnt so bad except for while hes in the air for that time he cant jump because hes not touching the ground



    ive been trying to change the code to work while hes just a little bit off the ground but im stuck, and my changes are not working correctly

    how should i do that??
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I would say give the controller a leeway timer. I haven't look at the code in question, but for example: If the original code says
    Code (csharp):
    1.  
    2. function FixedUpdate() {
    3. . . .
    4. if (Input.GetButtonDown("Jump")  isGrounded) {
    5. Jump();
    6. }
    7. . . .
    8. }
    then you might try this:
    Code (csharp):
    1.  
    2. var jumpLeeway : float = 0.25; //time, in seconds, after the controller has left the ground in which the player can still jump
    3. private var jumpTimer : float = -9999;
    4.  
    5. function FixedUpdate() {
    6. . . .
    7. if (isGrounded) {
    8. jumpTimer = Time.time;
    9. }
    10. if (Input.GetButtonDown("Jump")  Time.time <= jumpTimer + jumpLeeway) {
    11. Jump();
    12. }
    13. ...
    14. }
    15.