JonneOpettaja

WheelControls.cs

Feb 4th, 2019
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class WheelControls : MonoBehaviour {
  5.  
  6.     public float maxSpeed;
  7.     public float acceleration;
  8.     public float rotationAcceleration;
  9.  
  10.     private float horizontalVelocity;
  11.     private Rigidbody2D thisRigidBody;
  12.     private float direction;
  13.     private GameObject rengas;
  14.  
  15.     void Start () {
  16.         thisRigidBody = this.GetComponent<Rigidbody2D> ();
  17.     }
  18.  
  19.     void Update () {
  20.         direction = Input.GetAxis ("Horizontal");
  21.         horizontalVelocity = System.Math.Abs (thisRigidBody.velocity.x);
  22.  
  23.         //kaksi tapaa kiihdyttää: AddForce ja AddTorque
  24.         if (horizontalVelocity < maxSpeed) {
  25.                 // thisRigidBody.AddForce (new Vector2(direction, 0) * acceleration);
  26.                 thisRigidBody.AddTorque (-direction * rotationAcceleration);
  27.             }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment