- Home /
Have falling object exit from a collider after collision?
Hello Devs,
I have a falling object but at times it gets stuck upon colliders. Now sometimes there are also adjacent colliders, hence it should find a pathway to exit the collider and proceed it's journey. Now I made a solution if the case is just one collider and no neighbouring colliders blocking the way.
SOLN for one Collider :
void OnCollisionEnter(Collision hit)
{
if(hit.collider.tag == "ROCK")
{
ROCK = true;
col_pos = this.transform.InverseTransformPoint(hit.transform.position);
col_pos.Normalize();
col_pos = new Vector3((-col_pos.x),0,(-col_pos.z));
}// rigidbody.AddForce(col_pos * reqForce * Time.deltatime);
}
What I do is I take the relative position of the collider in respective to this transform and calculate the exact opposite direction. This works like a gel, but I need to find a pathway to exit in order to continue falling, it there is another hindrance on the way.
Thank you,
ScreenShot :
This is an image of the player falling towards the ground. http://postimage.org/image/vmnfmtljt/
Fattie - This is an image of the gameobject(player) falling towards the ground under the force of gravity. http://postimage.org/image/vmnfmtljt/
you don't need to use a script for what you are trying to achieve. just make sure you have colliders on your objects and apply a rigidbody to your player so you can have gravity. that's all you need.
I get that. But it just get held. I mean it stalls. I want to prevent stalling. I have rigidbody also.
so it's colliding with objects that don't exist, therefore causing a stall? make sure you check all the platforms in your scene. you might have a platform with the mesh renderer turned off that you don't realize.? i'm trying to imagine this so i can help you better.
$$anonymous$$killian, thanks for you effort to help me. I highly appreciate it. So, the player hitting the character is part of the gameplay but I do not want the player to stall there which would stall the entire game. I hope I am clear here.
Answer by ScroodgeM · Aug 30, 2012 at 09:58 PM
more correct to use this instead of collider's pivot if you want realistic movements
use triggers instead of colliders if you totally control moves
you should apply 'AddForce' every FixedUpdate(), not just once
using OnColliderStay can give better result cause it will call EVERY frame you are in collision
manually avoid situations when you object will got two opposite forces - this will cause object to stuck
Answer by MathieuBarbier · Aug 27, 2012 at 08:03 PM
Maybe you can give it a little push by adding a velocity in the same direction ?
Well nope. I do not think I would work. It would just get stuck.
Your answer
Follow this Question
Related Questions
Movement around a huge object by avoiding obstacles 1 Answer
help with AI avoidance script 0 Answers
dynamic node driven room based AI 1 Answer
AI question, characters escaping from light 0 Answers
Raycast problems in my AI 1 Answer