Search Unity

Forward or Backwards movement

Discussion in 'Scripting' started by peanutt, Mar 4, 2014.

  1. peanutt

    peanutt

    Joined:
    Nov 3, 2009
    Posts:
    28
    Heyas,
    Working on a skateboard game following some tutorials. This code is for when the skater has come back down after being vertical.
    What i want is when the skater hits the ramp to keep moving in the direction he is facing whether its forward or backward.
    Currently he translates forward no matter what direction he lands like it says to in the code. I cant work out how do what im after..If anyone has some hints or tips for what im looking to do that would be most appreciated.

    Code (csharp):
    1. if ( vertical  character.isGrounded )
    2.     {
    3.         vertical = false;
    4.         trans.forward = -trans.forward;
    5.          speed *= -1;      
    6.                    
    7.         var skaterRot = Vector3.Dot(trans.forward, skater.forward);
    8.         if (Mathf.Abs(skaterRot) < oneEightyThreshold)
    9.             Fall();
    10.         else if (vertRotation > 180.0 * oneEightyThreshold)
    11.         {
    12.             var multiplier = Mathf.Round(vertRotation / 180.0);
    13.        
    14.             // Player successfully rotated around
    15.             addPoints = oneEightyPoints * multiplier;
    16.             trickPoints.Add(addPoints);
    17.             trickLabel.Add(String.Format("{0}! +{1}", 180 * multiplier, addPoints));
    18.         }
    19.         skater.forward = trans.forward;
    20.            
    21.     }