Created
March 15, 2011 03:49
-
-
Save LoganBarnett/870280 to your computer and use it in GitHub Desktop.
TankMovement example in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using Finput; | |
// using Input; | |
public class TankMovement : MonoBehaviour | |
{ | |
public GameObject wheels; | |
public float speed = 100.0f; | |
public float breaking = 50.0f; | |
float List<WheelCollider> wheelColliders; | |
void Start() | |
{ | |
wheelColliders = new List<WheelCollider>(); | |
foreach (Transform child in wheels.transform) | |
{ | |
wheelColliders.Add(child.GetComponent<WheelCollider>()); | |
} | |
void Update() | |
{ | |
var input = Input.GetAxis("Move"); | |
var movement = input * speed * Time.deltaTime; | |
var antiMovement = breaking * (1 - Mathf.Abs(input)) * Time.deltaTime; | |
// Debug.Log(wheelColliders[0].rpm); | |
foreach (var wheel in wheelColliders) | |
{ | |
wheel.motorTorque = movement; | |
wheel.brakeTorque = antiMovement; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment