Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Help the circle find the text! Its for a good cause!

Author
Message
frostyrootbeer
21
Years of Service
User Offline
Joined: 23rd Dec 2002
Location: Afghanistan
Posted: 28th Jan 2003 06:13
As you see i have been making some modifications to one of the DB tutorials, but have encountered a problem
I wan't to display "You got the health" when the user brings the circle over the "health pickup" text, but the way I have it set up you have to get it exactly on the coordinates to trigger the event or you can trigger wrongly. Is there a way to display the text if the user gets the circle in a coordinate box or something? Thanks in advance.



words to live by.... Newsgeek.tripod.com
Fluffy Paul
21
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 29th Jan 2003 18:54
What you need to do is keep track of the size of the "circle" which I assume is the object the player is controlling, and you have to know how large a target object is. There are two ways you can detect for a collision: Using a square collision zone and using a circular one.
A square collision zone is simple: it has a left and right x coordinate and a top and bottom y coordinate. To check if something (at coordinates x,y) is in the zone you use this if statement:



If two things use a square zone then you have to check twice. Say it's a bullet and another sprite. The first thing you do is work out which one is smaller. Now the first check is to see if the smaller sprite's top left corner is inside the larger sprite's zone, then you check if the smaller sprite's bottom right corner is in the same zone. If so then you can trigger a condition of your choice using IF statements.

Using a circular collision detection method basically involves calculating the range between two points on the screen. If the range is smaller than a certain value then the two objects have collided.
The formula for calculating the range between coordinates x1,y1 and x2,y2 is:

((x1-x2)^2 + (y1-y2)^2)^0.5

Note - no trigonometry! Although raising to the power of 0.5 is the same as doing the square root.

Each of your objects that uses this circular collision detection should have a collision range assigned to them. When you've worked out the range between two points you should check both objects to see if the range is less than their collision range. If this is so then BOTH objects have collided (not just the one who's collision radius was lower than the range)!

Ending a sentence with a French word is so passé
frostyrootbeer
21
Years of Service
User Offline
Joined: 23rd Dec 2002
Location: Afghanistan
Posted: 30th Jan 2003 01:45
Thanks very much

equation for any multiplayer fps
the best weapon in the game = "noob cannon"

Login to post a reply

Server time is: 2024-09-19 02:58:05
Your offset time is: 2024-09-19 02:58:05