cwisbg

SkiCtrlr

Mar 1st, 2017
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class skiSimple1 : MonoBehaviour {
  5.     public GameObject Body;
  6.     Rigidbody BodyRb;
  7.  
  8.     public bool IsGrounded;
  9.     private Rigidbody rb;
  10.     public float Speed = 100.0f;
  11.     public float RotateSpeed = 100.0f;
  12.     public float FlipSpeed = 100.0f;
  13.     public float BoostSpeed = 200.0f;
  14.     public float JumpPower = 100.0f;
  15.        
  16.     void Start () {
  17.         rb = GetComponent<Rigidbody>();
  18.         BodyRb = Body.GetComponent<Rigidbody>();
  19.     }
  20.     void OnCollisionStay (Collision collisionInfo)
  21.     {
  22.         IsGrounded = true;
  23.     }
  24.  
  25.     void OnCollisionExit (Collision collisionInfo)
  26.     {
  27.         IsGrounded = false;
  28.     }
  29.  
  30.     void FixedUpdate() {
  31.         float moveHorizontal = Input.GetAxis ("Horizontal");
  32.         float moveVertical = Input.GetAxis ("Vertical");
  33.         if (IsGrounded){
  34.            
  35.             if (Input.GetKey (KeyCode.Space)) {
  36.                 rb.AddRelativeForce (transform.up * JumpPower);
  37.             }
  38.             rb.AddForce (transform.forward * moveVertical * Speed);
  39.             rb.AddTorque (transform.up * moveHorizontal * RotateSpeed);
  40.             rb.AddTorque (transform.right * moveVertical * FlipSpeed*0.1f);
  41.             rb.angularDrag= 2.0f;
  42.  
  43.             BodyRb.AddForce(transform.forward * moveVertical * Speed);
  44.         }
  45.         else {
  46.             rb.angularDrag = 0.0f;
  47.             //rb.AddTorque (transform.right * moveVertical * FlipSpeed);
  48.             rb.AddTorque (transform.up * moveHorizontal * RotateSpeed*0.1F);
  49.             BodyRb.AddTorque(transform.right * moveVertical * Speed);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment