- Home /
Detect when object in not colliding with collider.
hi frnds
i m wondering, is there any way to detect that object in not colliding. i m making penalty shootout. so when my ball enters in goal post texture will appear "GOAL". and when ball is outside of goal post after kick it will display "Miss"
thanx regards
simple way is to add some triggers around the goal post, same way to when it hits the net when ever they hit those it will display miss, you'll need 3 more triggers one on the left of the goal post, one on the right and one on the top
thanx for replay theUndeadEmo and Fattie
i have already tried but having problems like.
when ball goes inside goalpost and bounce back to missed collider this will display both texture."GOAL And $$anonymous$$issed"
and there's area between goal keeper and player. if player kick slow and ball stops before it reach to goal post. then how can i detect that it is miss.
Thanx again
You can make a timer (in code), and if the ball dont get anywhere at the end of the timer, it says miss (or whatever you want). I am new to coding, and i never had to make a timer so i forgot how to make it. I think there is a page explaining it in unity scripting reference, "Overview" section. Alternatively you can make the player lose if the goal keeper touches the ball, but if the player kicks the ball very slowy but far from the goal keeper it probably will not touch it, that depends on your AI.
thanx Leandro247
that's exactly what i thought. and asked this que..
and Fattie
my GOAL collider is already inside goal pose where NET is. still getting prob
isn't there is any code which can detect that object is not colliding with GOAL collider.
thanx again guys
Answer by Fattie · Sep 17, 2012 at 02:19 PM
box collider shown in red.
goal!
not goal !
Was mentioned, how to do a timer?
person kicks the ball ... then call this:
Invoke( "DisplayNoGoal" 1.0 );
function goal()
{
person does in fact get a goal
ie the trigger (red) was triggered
CancelInvoke( "DisplayNoGoal" );
actually yell "goa"
}
function DisplayNoGoal()
{
display something like you missed!
}
hey Fattie sorry for late replay i have que. those green boxes are also a collider ??
or only the red one.??
sure.
but i having little prob here .
can't cancel invoke. it everytime execute the function in invoke. even if i goal.
in goal collider i i called goal function witch include CancelInvoke . but i don't why its not working.
am i missing something ??
hoenstly this question is answered, nobody will look at it any more
I suggest you start NEW QUESTION, "problem with cancelling on goal" and carefully INCLUDE YOUR COD$$anonymous$$
I am sure someone will answer that new question very fast.
I hope it helps!
@Fattie What if the ball hits on the GoalPost ans bounces back? I mean there is no collider/trigger befor the goal post so, if the the ball hits on solid frame of goal post and bounces and returns to the player side, it would be a miss, still not to be counted. How to deal with it?
Answer by harko12 · Sep 17, 2012 at 07:53 PM
The only way I could think of checking that an object was NOT colliding is to go through the OnColliderEnter and OnColliderExit and set a flag when you are collided with the thing you want to check.
kind of like
void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.gameObject.CompareTag("ColliderYouWantToCheck"))
{
bool IAmCollidedWithCollider = true;
}
}
void OnCollisionExit(Collision collisionInfo)
{
if (collisionInfo.gameObject.CompareTag("ColliderYouWantToCheck"))
{
bool IAmCollidedWithCollider = false;
}
}
That said, that probably isn't the most efficient way, but it seems like it would work.
when the ball collides with the Goal collider it should cancel the DisplayNoGoal()
function OnTriggerEnter(hit : Collider){ if(hit.gameObject.tag == "Ball") {
CancelInvoke("DisplayNoGoal");// this function is called from here when person does in fact get a goal..to cancel the DisplayNoGoal()
}
}
// when the ball is kicked the Invoke function executes as following. if(countBalls.ballcount==1){
Invoke( "DisplayNoGoal", 3.0);
}
function DisplayNoGoal() { print("goal missed"); goal$$anonymous$$issed.enabled = true; } the problem here is when the person kicks the ball the invoke function executes and delay for 3 seconds but even if the goal is done by the person the invoke function is not getting canceled...
Answer by aksh2143 · Sep 10, 2015 at 09:10 AM
What if the ball hits on the GoalPost ans bounces back? I mean there is no collider/trigger befor the goal post so, if the the ball hits on solid frame of goal post and bounces and returns to the player side, it would be a miss, still not to be counted. How to deal with it?
Your answer
Follow this Question
Related Questions
Ball getting slow down in collision 0 Answers
The ball getting slow down and slicing. 0 Answers
Terrain collision problem 1 Answer
Collision Enter one of the objects ? 1 Answer