Computer Science Canada Need help with collision detection on a rotated object |
Author: | masterofcode [ Sun Jan 11, 2015 12:31 pm ] | ||
Post subject: | Need help with collision detection on a rotated object | ||
What is it you are trying to achieve? I am making a driving simulator and need to use fail the user when they go off the road. What is the problem you are having? My car rotates using Pic.Rotate. I need to find a way to detect the collision based on the newly positioned image. My background if a large green box with roads drawn on top. Describe what you have tried to solve this problem There would be too many cases to use regular collision detection so I have tried to use whatdotcolour. It works fine when the car is rotated at 0 degrees, 90 degrees, and 180 degrees but I cant think of a way to do it any other way. My car rotates 9 degrees at a time to avoid using sin and cos. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) The code below is an example program of how I used whatdotcolour. Could somebody please tell me how to fix this code so it doesn't matter the angle at which the object is rotated.
Please specify what version of Turing you are using 4.1.1 |
Author: | Insectoid [ Mon Jan 12, 2015 8:55 pm ] |
Post subject: | RE:Need help with collision detection on a rotated object |
This requires line-line collision. It uses a lot more math than rectangular collisions. Fortunately, you've probably learned this math in your Advanced Functions class if you've taken it. You have to check every line in object A to find out if it intersects with any lines in object B. You also might need to check if object A is completely inside object B. |