- Home /
Making force 0 at some point.
I am adding force(for projectile motion) once i release my mouse button.
if(Input.GetMouseButtonUp(0))
rigidbody.AddRelativeForce(10, 10, 10);
Once it reaches the trigger point i want this force to be 0 .i.e the ball should fall down with the gravity. So how to make this force 0?
PS : The trigger point is somewhere far.
Answer by sparkzbarca · Mar 11, 2013 at 09:51 AM
is the trigger an actual object?
basically you need to add a bool AND together the if statement with the bool and change the bool based on the trigger.
public bool TriggerHit = false;
if(input.getmousebuttonup(0) && TriggerHit == false)
{
//addforce
}
//you can add something to do here if the trigger is hit
or you can just do nothing and simply stop adding force
//script atttached to gameobject with trigger collider
void OnTriggerEnter(collider ColliderOfObject)
{
if (ColliderofObject.gameobject.tag == "name of your ball")
{
ColliderofObject.gameobject.getComponent<Script That adds force>().TriggerHit = true;
}
}
This is not working. I think because if(input.getmousebuttonup(0)) is called only once. Even if the bool becomes true there will not be any change.
do you just want to remove that force?
colliderofobject.gameobject.rigidbody.addrelativeforce(-10,-10,-10);
or
colliderofobject.gameobject.rigidbody.gravity = true;
I'm not sure what your trying to accomplish.
however if you know how to remove it in the script itself like right after you do it.
Take that code, paste it into the if statement inside the ontriggerenter
that is on trigger enter check to see if what hit the trigger was this ball object and if it is. Begin messing with the ball now thats its at the trigger point.
Thanks for the answer. I have made force 0 by making rigidbody.velocity = 0. And now it is working exactly how i wanted.
Your answer
Follow this Question
Related Questions
Shoot projectile according to rotation 2 Answers
Shooting a cannonball. 6 Answers
How to control the speed of the projectile motion? 1 Answer
Firing projectile in curve 1 Answer
Setting limits to my trajectory 2 Answers