- Home /
RigidBody Physics Flight Simulator Script Help
Hi, I am new to Unity, and I am currently working on a Rigidbody-based flight physics script. For the rotation, pitching, yawing of the plane, I am trying to use rigidbody.AddForceAtPosition. I save this script, but unity replies with this error saying: "Assets/Standard Assets/Scripts/General Scripts/FLightSim.js(21,49): BCE0023: No appropriate version of 'UnityEngine.Rigidbody.AddForceAtPosition' for the argument list '(UnityEngine.Vector3, UnityEngine.Transform, System.Object)' was found.”
I have no idea what is wrong with my script. Can somebody please give me a basic idea of principles of Rigid Body scripting please?
This is my current script:
var MaxThrottleStrength : float;
var LiftRatio : float;
var wingElevatorRight : Transform;
var wingElevatorLeft : Transform;
var ElevatorRight : Transform;
var ElevatorLeft : Transform;
var EngineStrength : float;
var ElevatorStrength : float;
var rotatestrength : float;
var EngineIncreaseSpeed : float;
private var Lift : float;
function Start(){
EngineStrength = 0;
}
function FixedUpdate(){
Lift = EngineStrength/10;
gameObject.rigidbody.AddRelativeForce ( Vector3.forward * EngineStrength);
gameObject.rigidbody.AddForceAtPosition ( Vector3.up * rotatestrength, wingElevatorRight, ForceMode.relativeForce );
gameObject.rigidbody.AddForceAtPosition ( Vector3.up * rotatestrength * -1, wingElevatorLeft, ForceMode.relativeForce );
gameObject.rigidbody.AddRelativeForce ( Vector3.up * Lift );
gameObject.rigidbody.AddForceAtPosition ( Vector3.up * ElevatorStrength, ElevatorRight, ForceMode.relativeForce );
gameObject.rigidbody.AddForceAtPosition ( Vector3.up * ElevatorStrength, ElevatorLeft, ForceMode.relativeForce );
}
function Update(){
if (Input.GetButton ("Vertical1")){
EngineStrength = EngineStrength + EngineIncreaseSpeed;
}
if (Input.GetButton ("Vertical2")){
ElevatorStrength = -20;
}
if (Input.GetButton ("Horizontal")){
rotatestrength = 20;
}
}
By the way, if anyone has an example flight script in java using rogodbody physics, I would love the help. This ( http://www.youtube.com/watch?v=r_7$$anonymous$$HkO_Fp$$anonymous$$ ) is the kind of thing I want my script to do.
Thank you in advance!
Answer by deadfroggy · Dec 21, 2012 at 12:57 AM
change everything that says "AddForceAtPosition", to just "AddForce"