Hi,
I have 2 round objects, A and B. Object A will move towards object B in a bullet behaviour. I want the object A to stop immediately on collision with object B. I am thinking of getting the collision coordinate so that I can set the position of object A. What is the best way to detect this precisely? Or any other approach that's better?
If they are the same size:
a.x+cos(angle(a.x,a.y,b.x,b.y))* distance(a.x,a,y,b.x,b.y)/2
a.Y+sin(angle(a.x,a.y,b.x,b.y))* distance(a.x,a,y,b.x,b.y)/2
This might help.
Thanks for the replies!
Gmoney newt
I tried your expression but it doesn't give the result I want. As in, sometimes it will be off by a few pixels. Does the collision polygon affect the results? The objects are different sizes.
They aren't the same size.
Just use the position the object had on collision....
newt
I tried that but sometimes the ball went further in. I guess it's due to collision polygon. The ball is round but there are only 8 collision points. I am guessing certain collision area is within the ball perimeter and thus it stopped slightly later. Do you have a solution to this? Not sure if adding more than 8 collision points is a good idea but that's the only solution I can think of.
Develop games in your browser. Powerful, performant & highly capable.
I found the solution. Basically I just use a dummy sprite to get the angle between the two balls and set the position towards that angle. Thanks for the tips guys.