Simple geometry problem with Unity and C # [closed]

1

I need to detect when a ball crosses a line (raycast + line renderer, for now) that will be between two points (like a soccer goal bow) ... but these points will move around the screen ... How can I detect that? that the ball crossed the line?

Any solution that opens my mind will be helpful for me

Thanks !!!!!

My current version: I thought to put a flag for when the raycast touches the ball, and if dsp stops touching it and the flag is true, it counts as a goal ... but it could happen that it touches the line, bounces with one of the clubs and stops playing the line ... in this case I would count it as goal without having crossed the line ... which would be wrong!

    
asked by Nogerad 23.01.2018 в 03:27
source

1 answer

0

I would do the following.

I would create those two objects, the father should be positioned in the center of the ball, but without being a child of the ball, you make it move via script, and the son should be in the center of the father, and he should also have a little collider, so the son's position would be:

X: Radio de la pelota + tamaño del collider Y: 0 Z: 0

(If your game is 3D, change the X to Z)

The father's script should make him rotate with the speed of the ball's rigidbody, he would do it with something like this:

transform.rotation=Quaternion.SetLookRotation(VelocidadDeLaPelota);

(Maybe it's the negative speed, Test the two ways)

(If your game is 3D or 2D, it may vary, but it's something like that)

And so the child object will pass right after the ball passes, and you can detect when the raycast collides with it and it's because it's over.

    
answered by 24.01.2018 в 05:41