Unity3D

Wing (Downforce)

//Provides downforce to the car, which helps reduce chances of car rolling.

using UnityEngine;
using System.Collections;

public class Wing : MonoBehaviour {

 Rigidbody body;
 public float liftCoefficient;
 
 void Start () {
 
 Transform trs = transform;
 while (trs != null && trs.GetComponent<Rigidbody>() == null)
 trs = trs.parent;

 if (trs != null)
 body = trs.GetComponent<Rigidbody>();
 }

 void Update () {
 
 if (body != null) {

 float lift = liftCoefficient * body.velocity.sqrMagnitude;
 body.AddForceAtPosition(lift * -transform.up, transform.position);
 }
 }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s