- Home /
Rigidbody AddForce Problem ?
Hello everyone, i have a Camera attached to cube. And we can fly, i want my cube to shake a bit when hit a building. So i put this code to the buildings ;
var Cube : GameObject; // I made this GameObject because i also want cube to animate but i didn't add this in here
var distance = 1000;
var a : int = 0; // this value is for making the action once
function Update()
{
if(a==0){
if (Vector3.Distance(transform.position,Cube.transform.position)<distance) // didn't use collider because if i do the plane is falling down and loosing the control.
{
a=1;
Cube.rigidbody.AddForce(Vector3(0,0,-50)*1000); // if i use this it adds force backwards and i can't take my plane control back, what should i use?
}
}
else{
}
}
And I ALSO tried using this but didn't work,any ideas ?
Cube.transform.Translate(Vector3.forward * -100 * Time.deltaTime);
What should i use, i'm using SAC plane control here it's ;
var YawSpeed = 30.0;
var TurnSpeed = 30.0;
var ElevateSpeed = 16;
var Acceleration = 200;
var MaxSpeed = 800;
private var Speed = 0.0;
function Update(){
if(Speed >= MaxSpeed){Speed=MaxSpeed;}
if(Speed 50 )
{
}
else {
}
}
Comment
it doesn't matter i tried every kinda value but no always can't take the control back
Best Answer
Answer by pyro · May 20, 2011 at 12:02 PM
You need to turn on the flag "isKinematic" for the rigidbody when you want it to be controlled through script and then turn it off when you want it to be controlled through physics.
Plus an easy way to do the camera shake is with iTween.ShakePosition