Skip to content

Instantly share code, notes, and snippets.

@nibasya
Last active August 13, 2019 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibasya/ce9a1d71d8fb7c720e9fe2f0eba7837d to your computer and use it in GitHub Desktop.
Save nibasya/ce9a1d71d8fb7c720e9fe2f0eba7837d to your computer and use it in GitHub Desktop.
An example using local class which groups some data
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DE10Controller : MonoBehaviour
{
[System.Serializable]
public class Wheel
{
public List<Rigidbody> wheels;
public float wheelMass = 600; // mass of each wheel pair without flange mass; i.e. twice the mass of 1 wheel without flange mass
}
public float targetVelocity; // target speed of rotation
public float torque; // a torque to be applied to each wheel
public Wheel wheel; // a group of setting related to wheels
// Start is called before the first frame update
void Start()
{
foreach(Rigidbody rb in wheel.wheels)
{
rb.mass = wheel.wheelMass;
}
}
// Update is called once per frame
void Update()
{
foreach (Rigidbody rb in wheel.wheels)
{
rb.mass = wheel.wheelMass;
rb.AddTorque(0, 0, torque);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment