- Home /
slow addforce
in my scene I have a ball that is thrown, so I added a addforce want you to slow down when it touches the ground its strength to a stop. I tried with rigidbody.sleep () but I do not like it stops abruptly. How can I do?
public var speed : float;
private var bar : float = 25;
static var myInt = 0;
public var sfera : GameObject;
public var coord : Vector3 = new Vector3 (0,5,5);
public var forza : ForceMode;
public var max : int = 100;
public var min : int = 0;
static var count : int = 0;
static var click : boolean = false;
function Start(){
}
function Update(){
if(/*Input.GetMouseButton(0) && count == 0*/ click == true && count == 0){
speed += bar * Time.deltaTime;
myInt = Mathf.FloorToInt(speed);
if(myInt >= max){
myInt = 100;
}
print(myInt);
}
if(Input.GetMouseButtonUp(0)){
click = false;
sfera.rigidbody.AddForce((coord*myInt)/2,forza);
myInt = min;
//count += 1;
}
gameObject.Find("Main Camera").SendMessage("Follow");
}
function OnMouseDown(){
// if(click == false){
click = true;
//}
}
function OnMouseUp(){
count += 1;
lerp.pp = true;
}
function OnCollisionEnter(pavimento:Collision)
{
if(pavimento.gameObject.tag == "pavimento")
{
coord = new Vector3 (0,0.01,0.01);
}
}
'Please remove unnecessary whitespace. The code is unreadable.
Answer by robertbu · Jul 24, 2013 at 04:36 AM
If I understand your question correctly, the easiest thing to do would be to setup the physic materials of both the ball and the floor so that the ball behaves like you want:
http://docs.unity3d.com/Documentation/Components/class-PhysicMaterial.html
The physic material is set in the collider of the objects. You can get a standard set of physic materials to start by going to the 'Assets' menu and selecting Import Package/Physic Materials.
Your answer
Follow this Question
Related Questions
Why is velocity checking intensive? 0 Answers
Rigidbody Addforce cancels out Rigidbody velocity..maybe? 0 Answers
Gravitational pull without losing speed 1 Answer
Rigidbody y velocity is stuck on 0, gravity is not turned off. 2 Answers
Why does writing to rigidbody.velocity after AddForce stop my rigidbody moving? 4 Answers