Reputation:
I never used the isKinematic
property, the object has 8 wheel colliders, and the object's mass is 20000.
I tried every combination; I used x y z for adding force,
Obj.GetComponent.<Rigidbody>().AddRelativeTorque( V*(spd)*1000, 0,0);
,
but none of them worked! The plane just stayed still.
What could be the problem?
Here is my code:
var Obj : Rigidbody;
var zrotForce : int = 1;
var MaxRot : int = 90;
var MinRot : int = -90;
var rotupForce : int = 1;
var speed : float;
var speedincrease : float;
var speeddecrease : float;
var Maxspeed : int;
var Minspeed : int;
var takeoffspeed : int;
var lift : int;
var minlift : int;
var hit = false;
function Start () {
InvokeRepeating("Speed", .1, .1);
}
function Speed(){
if (Input.GetKey(KeyCode.Space)){
Mathf.Repeat(1,Time.time);
speed=speed+speedincrease;
}
if (Input.GetKey(KeyCode.LeftAlt)){
Mathf.Repeat(1,Time.time);
speed=speed-speeddecrease;
}
}
function Update () {
var spd = Obj.velocity.magnitude;
//Obj.GetComponent.<Rigidbody>().AddRelativeForce(0,0,-speed);
H=(Input.GetAxis ("Horizontal"))*zrotForce;
if (H){
Obj.GetComponent.<Rigidbody>().AddRelativeTorque(H*(spd/100), 0, 0);
}
V=(Input.GetAxis ("Vertical"))*rotupForce;
if (V){
Obj.GetComponent.<Rigidbody>().AddRelativeTorque( V*(spd)*1000, 0,0);
}
if(Maxspeed<=speed){
speed=Maxspeed;
}else{
speed=speed;
}
if(Minspeed>=speed){
speed=Minspeed;
}else{
speed=speed;
}
if (speed<takeoffspeed){
Obj.GetComponent.<Rigidbody>().AddForce(0,minlift,0);
}
if(speed>takeoffspeed){
Obj.GetComponent.<Rigidbody>().AddForce(0,lift,0);
}
if (Obj.GetComponent.<Rigidbody>().rotation.z>MaxRot){
Obj.GetComponent.<Rigidbody>().rotation.z=MaxRot;
}
if (Obj.GetComponent.<Rigidbody>().rotation.z<MinRot){
Obj.GetComponent.<Rigidbody>().rotation.z=MinRot;
}
}
Upvotes: 1
Views: 5815
Reputation: 2187
According to your description you enabled the isKinematic
option for your rigidbody.
But if you take a look into Unitys documentation it says:
If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. The rigidbody will be under full control of animation or script control by changing transform.position.
So basically it won't move unless you use transform.position
in your scripts.
Reference:http://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html
Upvotes: 1
Reputation: 76
There are 2 things because of which the force or the torque is not working :-
1) The mass of your rigidbody is way too high. So you have to either change its mass or increase the force. For example, the force required to move an object with mass 1 unit has to be between 100-200 or maybe more based on the requirement.
2) When a rigidbody is declared kinematic then you can only change its transformation using script or animation. If you don't want the rigidbody to be influenced by the gravity and keep floating then just uncheck the isGravity and isKinematic (This will keep the object in air, also allowing you to influence it with force or torque as required.).
Upvotes: 1
Reputation: 135
Unity doesn't like large masses. you really shouldnt go over 10 according to their docs. Personally i create a sort of scale, so 10 is the heaviest object in the game and 0 is still 0.
also, Just a word of advice, i wouldn't GetComponent<> every frame, this will get wastefull as you build your game more. its usually better to do somethig like this:
private RigidBody rigidBody;
void Start () { rigidBody = gameObject.GetComponent<RigidBody> (); }
that way from your Update() you can just call
rigidBody.doSomething
Upvotes: 0