Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using CnControls;
- public class controller : MonoBehaviour {
- public float speedForce = 5f;
- float torqueForce = -100f;
- public float driftFactor = 0.98f;
- void Start () {
- }
- void Update () {
- Rigidbody2D rb = GetComponent<Rigidbody2D> ();
- rb.velocity = ForwardVelocity () + RightVeLocity () * driftFactor;
- rb.AddForce ( transform.up * speedForce );
- }
- void FixedUpdate () {
- Rigidbody2D rb = GetComponent<Rigidbody2D> ();
- rb.velocity = ForwardVelocity () + RightVeLocity () * driftFactor;
- rb.angularVelocity = CnInputManager.GetAxis ("Horizontal") * torqueForce;
- }
- Vector2 ForwardVelocity () {
- return transform.up * Vector2.Dot( GetComponent<Rigidbody2D>().velocity, transform.up );
- }
- Vector2 RightVeLocity () {
- return transform.right * Vector2.Dot( GetComponent<Rigidbody2D>().velocity, transform.right );
- }
- private void OnTriggerStay2D (Collider2D col) {
- if (col.tag == "ice") {
- driftFactor = 1f;
- }
- }
- private void OnTriggerExit2D (Collider2D col) {
- if (col.tag == "ice") {
- driftFactor = 0.98f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement