Search Unity

Wall jumping error 3d

Discussion in 'Scripting' started by keepthachange, Dec 3, 2014.

  1. keepthachange

    keepthachange

    Joined:
    Oct 15, 2014
    Posts:
    87
    okay i have a custom third person controller and when i was playing around with it in my game to see if it was working right i came across a problem wall jump works fine but if i stand in one place ( like the middle of the stage) and start jumping ( mashing jump button) then start moving toward a wall he goes straight up it im trying to make him jump hit a wall turn around jump off other wall (it works fine) just the standing in one spot and mashing jump makes him able to climb walls with out haveing to to wall jump off another wall? my game is 3D or 2.5 d
    i dont know the dif?

    HERE'S THE SCRIPT

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ThirdPersonController : MonoBehaviour {
    5.    
    6.     public AnimationClip idleAnimation;
    7.     public AnimationClip fallAnimanton;
    8.     public AnimationClip walkAnimation;
    9.     public AnimationClip runAnimation;
    10.     public AnimationClip jumpPoseAnimation;
    11.     public AnimationClip edgeAnimation;
    12.     public AnimationClip slamAnimation;
    13.    
    14.     public float walkMaxAnimationSpeed = 0.50f;
    15.     public float trotMaxAnimationSpeed = 0.70f;
    16.     public float runMaxAnimationSpeed = 1.0f;
    17.     public float jumpAnimationSpeed = 1.15f;
    18.     public float fallAnimationSpeed = 1.0f;
    19.     public float edgeAnimationSpeed = 1.0f;
    20.     public float slamAnimationSpeed = 1.0f;
    21.    
    22.     public float magnitude;
    23.     public float vel = 1;
    24.    
    25.     private Animation _animation;
    26.    
    27.     public enum CharacterState {
    28.         Idle = 0,
    29.         Walking = 1,
    30.         Trotting = 2,
    31.         Running = 3,
    32.         Jumping = 4,
    33.         edge = 5,
    34.         slam = 1,
    35.     }
    36.    
    37.     public CharacterState _characterState;
    38.    
    39.     // The speed when walking
    40.     float walkSpeed= 1.0f;
    41.     // after trotAfterSeconds of walking we trot with trotSpeed
    42.     float trotSpeed= 2.0f;
    43.     // when pressing "Fire3" button (cmd) we start running
    44.     float runSpeed= 3.0f;
    45.    
    46.     float inAirControlAcceleration= 3.0f;
    47.    
    48.     // How high do we jump when pressing jump and letting go immediately
    49.     public float jumpHeight= 0.5f;
    50.    
    51.     // We add extraJumpHeight meters on top when holding the button down longer while jumping
    52.     public float extraJumpHeight = 2.5f;
    53.    
    54.     // The gravity for the character
    55.     float gravity= 20.0f;
    56.     float controlledDescentGravity = 10.0f;
    57.     // The gravity in controlled descent mode
    58.     float speedSmoothing= 10.0f;
    59.     float rotateSpeed= 500.0f;
    60.     float trotAfterSeconds= 3.0f;
    61.    
    62.     bool canJump= true;
    63.     bool canControlDescent = true;
    64.     bool canWallJump = true;
    65.    
    66.     private float jumpRepeatTime= 0.05f;
    67.     private float jumpTimeout= 0.15f;
    68.     private float groundedTimeout= 0.25f;
    69.     private float wallJumpTimeout = 0.15f;
    70.    
    71.     // The camera doesnt start following the target immediately but waits for a split second to avoid too much waving around.
    72.     private float lockCameraTimer= 0.0f;
    73.    
    74.     // The current move direction in x-z
    75.     private Vector3 moveDirection= Vector3.zero;
    76.     // The current vertical speed
    77.     private float verticalSpeed= 0.0f;
    78.     // The current x-z move speed
    79.     private float moveSpeed= 0.0f;
    80.    
    81.     // The last collision flags returned from controller.Move
    82.     private CollisionFlags collisionFlags;
    83.    
    84.     // Are we jumping? (Initiated with jump button and not grounded yet)
    85.     public static bool jumping= false;
    86.     private bool jumpingReachedApex= false;
    87.    
    88.     // Are we moving backwards (This locks the camera to not do a 180 degree spin)
    89.     private bool movingBack= false;
    90.     // Is the user pressing any keys?
    91.     private bool isMoving= false;
    92.     // When did the user start walking (Used for going into trot after a while)
    93.     private float walkTimeStart= 0.0f;
    94.     // Last time the jump button was clicked down
    95.     private float lastJumpButtonTime= -10.0f;
    96.     // Last time we performed a jump
    97.     private float lastJumpTime= -1.0f;
    98.    
    99.    
    100.     // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
    101.     private float lastJumpStartHeight= 0.0f;
    102.    
    103.    
    104.     public static Vector3 inAirVelocity= Vector3.zero;
    105.    
    106.     private float lastGroundedTime= 0.0f;
    107.    
    108.    
    109.     private bool isControllable= true;
    110.    
    111.    
    112.    
    113.     // Average normal of the last touched geometry
    114.     Vector3 wallJumpContactNormal;
    115.     private float wallJumpContactNormalHeight;
    116.     // When did we touch the wall the first time during this jump (Used for wall jumping)
    117.     private float touchWallJumpTime = -1.0f;
    118.    
    119.     //Are we on a ledge
    120.     public static Transform ledgeTransform;
    121.     public static bool onLedge = false;
    122.    
    123.     private float lean = 0.0f;
    124.     private bool slammed = false;
    125.    
    126.    
    127.     void  Awake (){
    128.         moveDirection = transform.TransformDirection(Vector3.forward);
    129.        
    130.         _animation = GetComponent<Animation>();
    131.         if(!_animation)
    132.             Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
    133.        
    134.         if(!idleAnimation) {
    135.             _animation = null;
    136.             Debug.Log("No idle animation found. Turning off animations.");
    137.         }
    138.         if(!walkAnimation) {
    139.             _animation = null;
    140.             Debug.Log("No walk animation found. Turning off animations.");
    141.         }
    142.         if(!runAnimation) {
    143.             _animation = null;
    144.             Debug.Log("No run animation found. Turning off animations.");
    145.         }
    146.         if(!jumpPoseAnimation && canJump) {
    147.             _animation = null;
    148.             Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
    149.         }
    150.        
    151.     }
    152.    
    153.    
    154.    
    155.     void OnTriggerEnter(Collider other)
    156.     {
    157.        
    158.     }
    159.    
    160.    
    161.    
    162.     void  UpdateSmoothedMovementDirection ()
    163.     {
    164.         Transform cameraTransform= Camera.main.transform;
    165.         bool grounded= IsGrounded();
    166.        
    167.         // Forward vector relative to the camera along the x-z plane  
    168.         Vector3 forward= cameraTransform.TransformDirection(Vector3.forward);
    169.         forward.y = 0;
    170.         forward = forward.normalized;
    171.        
    172.         // Right vector relative to the camera
    173.         // Always orthogonal to the forward vector
    174.         Vector3 right = new Vector3(forward.z, 0, -forward.x);
    175.        
    176.         float v = Input.GetAxisRaw("Vertical");
    177.         float h = Input.GetAxisRaw("Horizontal");
    178.        
    179.         // Are we moving backwards or looking backwards
    180.         if (v < -0.2f)
    181.             movingBack = true;
    182.         else
    183.             movingBack = false;
    184.        
    185.         bool wasMoving= isMoving;
    186.         isMoving = Mathf.Abs (h) > 0.1f || Mathf.Abs (v) > 0.1f;
    187.        
    188.         // Target direction relative to the camera
    189.         Vector3 targetDirection= h * right + v * forward;
    190.        
    191.         // Smooth the speed based on the current target direction
    192.         float curSmooth= speedSmoothing * Time.deltaTime;
    193.        
    194.         // Choose target speed
    195.         //* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways
    196.         float targetSpeed= Mathf.Min(targetDirection.magnitude, 1.0f);
    197.        
    198.         if (onLedge && ledgeTransform)
    199.         {
    200.             _characterState = CharacterState.edge;
    201.             // Lock camera for short period when transitioning moving & standing still
    202.             lockCameraTimer += Time.deltaTime;
    203.             if (isMoving != wasMoving)
    204.                 lockCameraTimer = 0.0f;
    205.            
    206.             // We store speed and direction seperately,
    207.             // so that when the character stands still we still have a valid forward direction
    208.             // moveDirection is always normalized, and we only update it if there is user input.
    209.             //If the camera is behind/beside, right is right. Otherwise, right is left.
    210.             if(Vector3.Dot(Camera.main.transform.forward, transform.forward) < 0)
    211.                 moveDirection = h * ledgeTransform.right;
    212.             else
    213.                 moveDirection = h * -ledgeTransform.right;
    214.            
    215.             // Pick speed modifier
    216.             if (Input.GetButton ("Fire3"))
    217.             {
    218.                 targetSpeed *= runSpeed;
    219.             }
    220.             else if (Time.time - trotAfterSeconds > walkTimeStart)
    221.             {
    222.                 targetSpeed *= trotSpeed;
    223.             }
    224.             else
    225.             {
    226.                 targetSpeed *= walkSpeed;
    227.             }
    228.            
    229.             moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
    230.            
    231.             // Reset walk time start when we slow down
    232.             if (moveSpeed < walkSpeed * 0.3)
    233.                 walkTimeStart = Time.time;
    234.         }
    235.        
    236.         // Grounded controls
    237.         else if (grounded)
    238.         {
    239.             // Lock camera for short period when transitioning moving & standing still
    240.             lockCameraTimer += Time.deltaTime;
    241.             if (isMoving != wasMoving)
    242.                 lockCameraTimer = 0.0f;
    243.            
    244.             // We store speed and direction seperately,
    245.             // so that when the character stands still we still have a valid forward direction
    246.             // moveDirection is always normalized, and we only update it if there is user input.
    247.             if (targetDirection != Vector3.zero)
    248.             {
    249.                 // If we are really slow, just snap to the target direction
    250.                 if (moveSpeed < walkSpeed * 0.9f && grounded)
    251.                 {
    252.                     moveDirection = targetDirection.normalized;
    253.                 }
    254.                 // Otherwise smoothly turn towards it
    255.                 else
    256.                 {
    257.                     moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
    258.                    
    259.                     moveDirection = moveDirection.normalized;
    260.                 }
    261.             }
    262.             _characterState = CharacterState.Idle;
    263.            
    264.             // Pick speed modifier
    265.             if (Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift))
    266.             {
    267.                 targetSpeed *= runSpeed;
    268.                 _characterState = CharacterState.Running;
    269.                 if(magnitude > 0.1f)
    270.                     vel = 2;
    271.             }
    272.             else if (Time.time - trotAfterSeconds > walkTimeStart)
    273.             {
    274.                 targetSpeed *= trotSpeed;
    275.                 _characterState = CharacterState.Trotting;
    276.                 vel = 1.4f;
    277.             }
    278.             else
    279.             {
    280.                 targetSpeed *= walkSpeed;
    281.                 _characterState = CharacterState.Walking;
    282.                 vel = 1;
    283.             }
    284.            
    285.             moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
    286.            
    287.             // Reset walk time start when we slow down
    288.             if (moveSpeed < walkSpeed * 0.3f)
    289.                 walkTimeStart = Time.time;
    290.         }
    291.         // In air controls
    292.         else
    293.         {
    294.             // Lock camera while in air
    295.             if (jumping)
    296.                 lockCameraTimer = 0.0f;
    297.            
    298.             if (isMoving)
    299.                 inAirVelocity += targetDirection.normalized * Time.deltaTime * inAirControlAcceleration;
    300.         }
    301.        
    302.        
    303.        
    304.     }
    305.    
    306.     void ApplyWallJump ()
    307.     {
    308.         // We must actually jump against a wall for this to work
    309.         if (!jumping)
    310.             return;
    311.        
    312.         // Store when we first touched a wall during this jump
    313.         if (collisionFlags == CollisionFlags.CollidedSides)
    314.         {
    315.             touchWallJumpTime = Time.time;
    316.         }
    317.        
    318.         // The user can trigger a wall jump by hitting the button shortly before or shortly after hitting the wall the first time.
    319.         var mayJump = lastJumpButtonTime > touchWallJumpTime - wallJumpTimeout && lastJumpButtonTime < touchWallJumpTime + wallJumpTimeout;
    320.         if (!mayJump)
    321.             return;
    322.        
    323.         // Prevent jumping too fast after each other
    324.         if (lastJumpTime + jumpRepeatTime > Time.time)
    325.             return;
    326.        
    327.        
    328.         if (Mathf.Abs(wallJumpContactNormal.y) < 0.2)
    329.         {
    330.             wallJumpContactNormal.y = 0;
    331.             moveDirection = wallJumpContactNormal.normalized;
    332.             // Wall jump gives us at least trotspeed
    333.             moveSpeed = Mathf.Clamp(moveSpeed * 1.5f, trotSpeed, runSpeed);
    334.         }
    335.         else
    336.         {
    337.             moveSpeed = 0;
    338.         }
    339.        
    340.         verticalSpeed = CalculateJumpVerticalSpeed (jumpHeight);
    341.         DidJump();
    342.         SendMessage("DidWallJump", null, SendMessageOptions.DontRequireReceiver);
    343.     }
    344.    
    345.     void  ApplyJumping (){
    346.         // Prevent jumping too fast after each other
    347.         if (lastJumpTime + jumpRepeatTime > Time.time)
    348.             return;
    349.        
    350.         if (IsGrounded()) {
    351.             // Jump
    352.             // - Only when pressing the button down
    353.             // - With a timeout so you can press the button slightly before landing      
    354.             if (canJump && Time.time < lastJumpButtonTime + jumpTimeout) {
    355.                 verticalSpeed = CalculateJumpVerticalSpeed (jumpHeight);
    356.                 SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
    357.             }
    358.         }
    359.     }
    360.    
    361.    
    362.     void  ApplyGravity (){
    363.         if (isControllable)    // don't move player at all if not controllable.
    364.         {
    365.             // Apply gravity
    366.             bool jumpButton= Input.GetButton("Jump");
    367.            
    368.             // * When falling down we use controlledDescentGravity (only when holding down jump)
    369.             bool controlledDescent = canControlDescent && verticalSpeed <= 0.0f && jumpButton && jumping;
    370.            
    371.             // When we reach the apex of the jump we send out a message
    372.             if (jumping && !jumpingReachedApex && verticalSpeed <= 0.0f)
    373.             {
    374.                 jumpingReachedApex = true;
    375.                 SendMessage("DidJumpReachApex", SendMessageOptions.DontRequireReceiver);
    376.             }
    377.            
    378.             // * When jumping up we don't apply gravity for some time when the user is holding the jump button
    379.             // This gives more control over jump height by pressing the button longer
    380.             bool extraPowerJump = IsJumping () && verticalSpeed > 0.0f && jumpButton && transform.position.y < lastJumpStartHeight + extraJumpHeight;
    381.            
    382.             //Let go of the ledge
    383.             if (onLedge && jumpButton)
    384.             {
    385.                 onLedge = false;
    386.                 moveDirection = transform.forward;
    387.                 movingBack = true;
    388.             }
    389.            
    390.             if (controlledDescent)
    391.                 verticalSpeed -= controlledDescentGravity * Time.deltaTime;
    392.             else if (extraPowerJump)
    393.                 return;  
    394.             else if (IsGrounded ()|| onLedge)
    395.                 verticalSpeed = 0.0f;
    396.             else
    397.                 verticalSpeed -= gravity * Time.deltaTime;
    398.         }
    399.     }
    400.    
    401.     float  CalculateJumpVerticalSpeed ( float targetJumpHeight  ){
    402.         // From the jump height and gravity we deduce the upwards speed
    403.         // for the character to reach at the apex.
    404.         return Mathf.Sqrt(2 * targetJumpHeight * gravity);
    405.     }
    406.    
    407.     void  DidJump (){
    408.         jumping = true;
    409.         jumpingReachedApex = false;
    410.         lastJumpTime = Time.time;
    411.         lastJumpStartHeight = transform.position.y;
    412.         touchWallJumpTime = -1;
    413.         lastJumpButtonTime = -10;
    414.        
    415.         _characterState = CharacterState.Jumping;
    416.     }
    417.    
    418.     void  Update (){
    419.        
    420.         if (!isControllable)
    421.         {
    422.             // kill all inputs if not controllable.
    423.             Input.ResetInputAxes();
    424.         }
    425.        
    426.         if (Input.GetButtonDown ("Jump"))
    427.         {
    428.             lastJumpButtonTime = Time.time;
    429.         }
    430.        
    431.         UpdateSmoothedMovementDirection();
    432.        
    433.         // Apply gravity
    434.         // - extra power jump modifies gravity
    435.         // - controlledDescent mode modifies gravity
    436.         ApplyGravity ();
    437.        
    438.         // Perform a wall jump logic
    439.         // - Make sure we are jumping against wall etc.
    440.         // - Then apply jump in the right direction)
    441.         if (canWallJump)
    442.             ApplyWallJump();
    443.         // Apply jumping logic
    444.         ApplyJumping ();
    445.        
    446.         // Calculate actual motion
    447.         Vector3 movement = moveDirection * moveSpeed + new Vector3 (0, verticalSpeed, 0) + inAirVelocity;
    448.         movement *= Time.deltaTime;//moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0) + inAirVelocity
    449.        
    450.         magnitude = movement.magnitude;
    451.        
    452.        
    453.         // Move the controller
    454.         CharacterController controller = GetComponent<CharacterController>();
    455.         wallJumpContactNormal = Vector3.zero;
    456.         collisionFlags = controller.Move(movement);
    457.        
    458.         // ANIMATION sector
    459.         if(_animation) {
    460.             if(_characterState == CharacterState.edge)
    461.             {
    462.                 _animation[edgeAnimation.name].speed = edgeAnimationSpeed;
    463.                 _animation[edgeAnimation.name].wrapMode = WrapMode.ClampForever;
    464.                 _animation.CrossFade(edgeAnimation.name);
    465.                
    466.             }
    467.             if(_characterState == CharacterState.Jumping)
    468.             {
    469.                 if(!jumpingReachedApex) {
    470.                     _animation[jumpPoseAnimation.name].speed = jumpAnimationSpeed;
    471.                     _animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
    472.                     _animation.CrossFade(jumpPoseAnimation.name);
    473.                 } else {
    474.                     _animation[fallAnimanton.name].speed = -fallAnimationSpeed;
    475.                     _animation[fallAnimanton.name].wrapMode = WrapMode.ClampForever;
    476.                     _animation.CrossFade(fallAnimanton.name);              
    477.                 }
    478.             }
    479.             else
    480.             {
    481.                 if(controller.velocity.sqrMagnitude < 0.1f) {
    482.                     _animation.CrossFade(idleAnimation.name);
    483.                 }
    484.                 else
    485.                 {
    486.                     if(_characterState == CharacterState.Running) {
    487.                         _animation[runAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, runMaxAnimationSpeed);
    488.                         _animation.CrossFade(runAnimation.name);  
    489.                     }
    490.                     else if(_characterState == CharacterState.Trotting) {
    491.                         _animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, trotMaxAnimationSpeed);
    492.                         _animation.CrossFade(walkAnimation.name);  
    493.                     }
    494.                     else if(_characterState == CharacterState.Walking) {
    495.                         _animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, walkMaxAnimationSpeed);
    496.                         _animation.CrossFade(walkAnimation.name);  
    497.                     }
    498.                    
    499.                 }
    500.             }
    501.         }
    502.         // ANIMATION sector
    503.        
    504.         if(onLedge && ledgeTransform)
    505.         {
    506.             transform.rotation = Quaternion.LookRotation(-ledgeTransform.forward);
    507.         }
    508.        
    509.         // Set rotation to the move direction
    510.         else if (IsGrounded())
    511.         {
    512.             if(slammed) // we got knocked over by an enemy. We need to reset some stuff
    513.             {
    514.                 slammed = false;
    515.                 controller.height = 2;
    516.                 Vector3 temp = transform.position; // copy to an auxiliary variable...
    517.                 temp.y = 0.75f; // modify the component you want in the variable...
    518.             }
    519.            
    520.             transform.rotation = Quaternion.LookRotation(moveDirection);
    521.            
    522.         }  
    523.         else
    524.         {
    525.             if(!slammed)
    526.             {
    527.                 Vector3 xzMove= movement;
    528.                 xzMove.y = 0;
    529.                 if (xzMove.sqrMagnitude > 0.001f)
    530.                 {
    531.                     transform.rotation = Quaternion.LookRotation(xzMove);
    532.                 }
    533.             }
    534.         }  
    535.        
    536.         // We are in jump mode but just became grounded
    537.         if (IsGrounded())
    538.         {
    539.             lastGroundedTime = Time.time;
    540.             inAirVelocity = Vector3.zero;
    541.             if (jumping)
    542.             {
    543.                 jumping = false;
    544.                 SendMessage("DidLand", SendMessageOptions.DontRequireReceiver);
    545.             }
    546.         }
    547.     }
    548.    
    549.     void  OnControllerColliderHit ( ControllerColliderHit hit   ){
    550.         //    Debug.DrawRay(hit.point, hit.normal);
    551.         if (hit.moveDirection.y > 0.01f)
    552.             return;
    553.         wallJumpContactNormal = hit.normal;
    554.     }
    555.    
    556.     float  GetSpeed (){
    557.         return moveSpeed;
    558.     }
    559.    
    560.     public bool  IsJumping (){
    561.         return jumping;
    562.     }
    563.    
    564.     bool  IsGrounded (){
    565.         return (collisionFlags & CollisionFlags.CollidedBelow) != 0;
    566.     }
    567.    
    568.     void SuperJump (float height)
    569.     {
    570.         verticalSpeed = CalculateJumpVerticalSpeed (height);
    571.         collisionFlags = CollisionFlags.None;
    572.         SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
    573.     }
    574.    
    575.     void SuperJump (float height, Vector3 jumpVelocity)
    576.     {
    577.         verticalSpeed = CalculateJumpVerticalSpeed (height);
    578.         inAirVelocity = jumpVelocity;
    579.        
    580.         collisionFlags = CollisionFlags.None;
    581.         SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
    582.     }
    583.    
    584.     void Slam (Vector3 direction)
    585.     {
    586.         verticalSpeed = CalculateJumpVerticalSpeed (1);
    587.         inAirVelocity = direction * 6;
    588.         direction.y = 0.6f;
    589.         Quaternion.LookRotation(-direction);
    590.         CharacterController controller  = GetComponent<CharacterController>();
    591.         controller.height = 0.5f;
    592.         slammed = true;
    593.         collisionFlags = CollisionFlags.None;
    594.         SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
    595.     }
    596.    
    597.     public void GrabLedge(Transform ledge)
    598.     {
    599.         ledgeTransform = ledge;
    600.         onLedge = true;
    601.         jumping = false;
    602.         inAirVelocity = Vector3.zero;
    603.        
    604.     }
    605.    
    606.     Vector3  GetDirection (){
    607.         return moveDirection;
    608.     }
    609.    
    610.     public bool  IsMovingBackwards (){
    611.         return movingBack;
    612.     }
    613.    
    614.     public float  GetLockCameraTimer ()
    615.     {
    616.         return lockCameraTimer;
    617.     }
    618.    
    619.     bool IsMoving ()
    620.     {
    621.         return Mathf.Abs(Input.GetAxisRaw("Vertical")) + Mathf.Abs(Input.GetAxisRaw("Horizontal")) > 0.5f;
    622.     }
    623.    
    624.     bool  HasJumpReachedApex ()
    625.     {
    626.         return jumpingReachedApex;
    627.     }
    628.    
    629.     bool  IsGroundedWithTimeout ()
    630.     {
    631.         return lastGroundedTime + groundedTimeout > Time.time;
    632.     }
    633.    
    634.     bool IsControlledDescent ()
    635.     {
    636.         // * When falling down we use controlledDescentGravity (only when holding down jump)
    637.         bool jumpButton = Input.GetButton("Jump");
    638.         return canControlDescent && verticalSpeed <= 0.0 && jumpButton && jumping;
    639.     }
    640.    
    641.     void  Reset ()
    642.     {
    643.         gameObject.tag = "Player";
    644.     }
    645.    
    646. }
    647.  
     
    Last edited: Dec 3, 2014
  2. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
  3. keepthachange

    keepthachange

    Joined:
    Oct 15, 2014
    Posts:
    87
    Well now i know lol thx :)