- Home /
continuing an objects motion
so ive built a tornado and i have trigger colliders extending from the center that determin how an object that enters will be pulled and rotated around the tornado. so the problem im having is after an object is thrown out of the tornado once it exits the collider it just stops and falls to the ground. so i want it so if an object is thrown out of the collider it will continue with its motion and slowly come to a stop as it falls rather than imedietly. thanks
Answer by iJuan · May 12, 2018 at 11:44 PM
private void OnTriggerExit(Collider other) {
Rigidbody rigidbody = other.GetComponent<Rigidbody>();
//If you aren't moving your object with forces
Vector3 dir = other.transform.position - transform.position;
dir.y = 1.5f; //Some arbitrary value
//If you are moving your object using forces
Vector3 dir = rigidbody.velocity;
rigidbody.applyForce(dir.normalized * strength) ;
}
Where strength determines how far the object is thrown
im getting an error with apply force. also do i need to make a public float for strength?
$$anonymous$$y bad, the method is called AddForce
Just replace strength with any number you like, or make it a variable, your choice
I'd recommend you doing a C# Tutorial, there are lots on the web
First result on Google. Please do some research before posting in here. Thanks
im still confused on your script it doeset seem to be doing anything?
Your answer
Follow this Question
Related Questions
How to detect collision between 2 objects while checking are they the ones that need to collide? 1 Answer
How to add 2D collider in unity 4.6 0 Answers
How Does OnTriggerEnter() Work? 0 Answers
A script that auto generated the box collider around a 3d model 3 Answers
Why when i move the player object through the door the ontriggerenter/exit event are not fire ? 2 Answers