Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using CnControls;
  4.  
  5. public class controller : MonoBehaviour {
  6.  
  7.     public float speedForce = 5f;
  8.     float torqueForce = -100f;
  9.     public float driftFactor = 0.98f;
  10.  
  11.  
  12.  
  13.     void Start () {
  14.  
  15.     }
  16.  
  17.  
  18.     void Update () {
  19.         Rigidbody2D rb = GetComponent<Rigidbody2D> ();
  20.         rb.velocity = ForwardVelocity () + RightVeLocity () * driftFactor;
  21.         rb.AddForce ( transform.up * speedForce );
  22.  
  23.  
  24.     }
  25.  
  26.     void FixedUpdate () {
  27.         Rigidbody2D rb = GetComponent<Rigidbody2D> ();
  28.         rb.velocity = ForwardVelocity () + RightVeLocity () * driftFactor;
  29.  
  30.         rb.angularVelocity = CnInputManager.GetAxis ("Horizontal") * torqueForce;
  31.     }
  32.  
  33.     Vector2 ForwardVelocity () {
  34.         return transform.up * Vector2.Dot( GetComponent<Rigidbody2D>().velocity, transform.up );
  35.  
  36.     }
  37.  
  38.         Vector2 RightVeLocity () {
  39.             return transform.right * Vector2.Dot( GetComponent<Rigidbody2D>().velocity, transform.right );
  40.  
  41.     }
  42.     private void OnTriggerStay2D (Collider2D col) {
  43.         if (col.tag == "ice") {
  44.             driftFactor = 1f;
  45.         }
  46.    
  47.     }
  48.         private void OnTriggerExit2D (Collider2D col) {
  49.         if (col.tag == "ice") {
  50.             driftFactor = 0.98f;
  51.             }
  52.  
  53.  
  54.             }
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement