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.

DarkBASIC Discussion / circle math problem

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Dec 2007 18:03
hey guys!

Ive been working on this game called "barrel patrol", but have come across a problem.

First let me describe the game:
You are a tank. You play inside a circle of fire, which you can not leave. In the middle of that circle are 25 barrels, which are attacked by the fierce aliens of the undergrounds. You have to guard the barrels for 3 minutes, trying to blow up as many aliens as you can, and making sure, they dont steel your barrels.

Heres the function for the circle math, to keep the player inside it:




I have tried storing the old position of the player at the start of the loop, and if there is a collision(the radius is bigger than 240) it would position the player with the old positions instead of the new ones. But that made the player stick at the circle and not get loose again.

I have tried making the player bounce back until theres no collision, but then the weirdest thing you can possibly think of occured.

Finally, I just made the player die when it goes out of bounds, but that isnt fun anymore.

Does anyone know how to make a collision at the circle edge, without the errors at top occuring?

Many thanks!

Oooooops!!! I accidentally formated drive c.
RUCCUS
21
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 26th Dec 2007 19:12 Edited at: 26th Dec 2007 19:33
You could get the distance the player is past the allowed radius, and move them back by that distance (plus whatever buffer you want, if you want one).

<EDIT>

Actually that will cause sticking too. What you need to do is effect the user's x and y component individually. Then check for collision on each axis. If there's a collision on the x axis, stop effecting it. If on the y, stop effecting it as well. This way, if there's a collision on the x but not the y, the user will "slide" along the radius of the circle because the y will still increase.

This is what I threw together for the initial idea I suggested, dont have time to change it to the other one, but Ill post it anyways, it has some useful math functions in there that might help you (using vectors is faster than doing your own trig).



Sorry, no time to comment it.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Dec 2007 19:44
I`ll try it tomorrow, since I have to shut down but hey, thanks very much!!

Oooooops!!! I accidentally formated drive c.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Dec 2007 21:47 Edited at: 26th Dec 2007 23:50
@Ruccus
Your theory is good but unfortunately DBC can't do vectors

[edit]
Here's my solution.
I put it together as I wrote it so it might not be that great, but it does work


demons breath
22
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 27th Dec 2007 13:53
An alternative; when it reaches one side of the circle have it come on the opposite side instead... Calculate the angle from the centre and simply reverse it so that it's just inside the opposite side (obviously not still touching it as that would defeat the point)

"A West Texas girl, just like me"
-Bush
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 27th Dec 2007 15:37
I would think that a tank would suffer from fire damage if it goes into fire - why not simply let it take damage unti the player drives it back to the desired area ?

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Dec 2007 16:27
Quote: "An alternative; when it reaches one side of the circle have it come on the opposite side instead... Calculate the angle from the centre and simply reverse it so that it's just inside the opposite side (obviously not still touching it as that would defeat the point)"

you mean the tank would magically appear on the other side of the ring?

Whatever you do the key is measuring how far the tank is from the centre of the circle

heartbone
23
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 27th Dec 2007 16:57
Save the previous position.
Move the object to the new position.
Calculate the new distance to center squared:
NDTCS#= (x#-midx#)*(x#-midx#) + (z#-midz#)*(z#-midz#)
If NDTCS# > (240*240) then
move object back to previous position and update the display.

I'm unique, just like everybody else.
heartbone
23
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 27th Dec 2007 17:20
If your tank can not go in reverse at that point, then you'll need additional logic at the move object back to previous position section.

I'm unique, just like everybody else.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Dec 2007 21:30 Edited at: 27th Dec 2007 21:31
Quote: "I would think that a tank would suffer from fire damage if it goes into fire - why not simply let it take damage unti the player drives it back to the desired area ?"


If you make it suffer fire damage, but still live, the tank would just keep on going through the fire. Then you get back to the problem with the collision...

Quote: "Save the previous position.
Move the object to the new position.
move object back to previous position and update the display."


if you do that mate, the tank will get stuck on the "ring of fire" and burn to death. Now I would rather be shot than be burned. (That isn`t the point of this thread...)

I have made the tank bounce back double the speed it came in, but that doesn`t look good:



If I move it -5 instead of -10, it gets stuck. Now I think you are all thinking, why not bounce it back -6(or any other number smaller then -5)?

I you bounce it back smaller than it was before and the tank is right on the edge, it will back up into the the circle a little further next to it. And because it`s still a collision, it`s going to back itself away right out of the level.

Now lets all look at the possibility of putting collision boxes all around the circle. Firstly, it would take up tons of processing time. But secondly, I can use the "if object collision()=1" command:



I dont know what is more effective... What do you guys think of that?

Oooooops!!! I accidentally formated drive c.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Dec 2007 04:36
When I originally read this thread I put together an example and the saw that OBese87 had already posted one very similar and Ruccus had come up with the idea of adding a buffer, so I didn't post the example. After reading your last post, I'm confused as to what you want and don't want the tank to do.

You want the tank to stay within a certain radius from a center point, right?

If it goes beyond that radius, how do you want the tank to behave? I'll include the example I spoke of (modified for 3d). It doesn't use any collision, and I eliminated most of the floats to optimize a bit. When the tank reaches the outer edge, it will slide along the inside of the circle until it reaches the maximum it can go in either the x or z direction:




Enjoy your day.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 28th Dec 2007 09:52
Quote: "After reading your last post, I'm confused as to what you want and don't want the tank to do."


I`m just thinking of a solution with collision boxes.


Your code works perfectly! Congratulations, you have solved my problem!

Thanks a lot, mate!

Oooooops!!! I accidentally formated drive c.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Dec 2007 15:22
@Latch
I like the cylinder boundary, was wondering what that was
I tried TDK's "inside-out" trick on it but this made it disappear some of the time


Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Dec 2007 00:46
@Obese
You know this one! I've seen you suggest it to others - SET OBJECT disable culling!

I think a negative size value of a primative reverses the normals (turns the light reflection inside out). If the object is giant and the camera remains inside of it (like a skybox or skysphere), whatever faces are in view will be shown. But in my ring example, sometimes the camera is outside of the object so the faces on the outside of the object aren't drawn - so it appears to disappear (because of culling). So disabling culling will work better for this small ring as opposed to the "inside out" cylinder.

Enjoy your day.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Dec 2007 00:55 Edited at: 29th Dec 2007 00:56
@Latch
Quote: "You know this one! I've seen you suggest it to others - SET OBJECT disable culling!"

haha I know I know
I just didn't know that's what you'd done to get that ring (aka I ran the program without looking at it )
How come the top and bottom faces aren't visible?

Quote: "I think a negative size value of a primative reverses the normals (turns the light reflection inside out). If the object is giant and the camera remains inside of it (like a skybox or skysphere), whatever faces are in view will be shown. But in my ring example, sometimes the camera is outside of the object so the faces on the outside of the object aren't drawn - so it appears to disappear (because of culling). So disabling culling will work better for this small ring as opposed to the "inside out" cylinder."

hmm yeah I think I'll stick to disabling culling.

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Dec 2007 01:19
Quote: "I just didn't know that's what you'd done to get that ring "

If you set ghosting on an object, anything black will be completely transparent, and anything colored will let other colors pass through (based on the lack of intensity of the r g and b values - white should be completely opaque). So I just drew a red line in a black box and used that as the texture for the cylinder. I ghosted the cylinder and only the red line shows. The way the UV coords are on the cylinder, the line appears as a ring around the center of the object, and everything else is black.

Enjoy your day.
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 29th Dec 2007 11:59 Edited at: 29th Dec 2007 12:01

sorry didn't see this until after I posted

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Dec 2007 17:04 Edited at: 29th Dec 2007 17:59
Wow! I never thought of making a circle like that.

Here`s how I did it:




Oooooops!!! I accidentally formated drive c.

Login to post a reply

Server time is: 2026-07-06 08:23:26
Your offset time is: 2026-07-06 08:23:26