Skip to content

Instantly share code, notes, and snippets.

@LoganBarnett
Created March 15, 2011 03:49
Show Gist options
  • Save LoganBarnett/870280 to your computer and use it in GitHub Desktop.
Save LoganBarnett/870280 to your computer and use it in GitHub Desktop.
TankMovement example in C#
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