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 with static collision box

Author
Message
Johnny Bolt
19
Years of Service
User Offline
Joined: 30th Dec 2004
Location: South Jersey
Posted: 10th Feb 2005 10:40 Edited at: 10th Feb 2005 11:58
I'm not quite sure if I understand the make static collision box command. Can someone please explain the make static collision box and get static collision hit. Mainly what the commands require and how that applies to a 3D space.

What I am trying to accomplish is to know when an object touches a certain section of a 3D box. Would this be the correct way to accomplish this or is there another command that would make this easier. I don't need the sliding collision part of this at least not yet.
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 10th Feb 2005 16:01 Edited at: 10th Feb 2005 16:03
Hi Johnny, I'm not sure exactly what you are wanting to accomplish, but I am pretty sure a static collision box is probably not what you want. I haven't used static collision boxes myself, but my understanding is that they are used primarily to block of portions of your game world (like the edge or a cliff).

As far as detecting where one object touches another, well that's something DBPro doesn't do too well by itself. Based on the info you did provide, I can suggest two possibilities.

1) If you want a detailed collision on your box (i.e. down to a pixel or so), you might want to check around for dlls that can do this. I've read about a few,but I have no idea how they work, or how well they work.
2) If you just want a general collision area, like a side, you can;
a) Use math to calculate the collision side
b) Or, you can make a box from 6 plains and re-build the box as needed each frame (DBPro can easily handle this for even a few boxes, but it's a bit of programming). Then just check for collisions against each of the plains.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 10th Feb 2005 16:28
Johnny, Also take a look at this code. Again, I don't know if you want detail, or maybe just a side or an angle. This code returns the angle side the "Player" was hit on. You can adjust the angle granularity, but it costs Frame Rate to put it too high (and get little in return). This 'theory' could also be put to use in 3 dimensions instead of just 2 as in the demo here.



"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Johnny Bolt
19
Years of Service
User Offline
Joined: 30th Dec 2004
Location: South Jersey
Posted: 11th Feb 2005 12:28 Edited at: 11th Feb 2005 12:33
Thanks RiiDii for the response. Great little piece of code. Though it is not quite what I am looking for, it may come in handy later on down the road.

What I am looking for: I am making kind of a 3D Pong game (yea I know it's been done a thousand times but I am trying to teach my 12 year old some of the basics of programing and thought that would be a good place to start).

I want to write a piece of code that will chage the way the ball moves. I want to be able to affect it by where on the paddle it hits(ie: if it hits the left side of the face of the paddle, reverse the direction of the ball: if it hits in the middle of the paddle - bounce in the same direction (you get the idea?)).

I've created the paddle by using the command make object box and then set object collision to boxes. This does what I need it to as far as tracking the collisions.

Is there anyway to know where on the box it hits?

The only true failure is not to try at all...
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 11th Feb 2005 14:55 Edited at: 11th Feb 2005 15:07
Sure - it can be easily done. Just make the paddle out of 3 boxes. Keep the three boxes in sync with each other (aligned) and the ball does what you program it to based on which box it collides with. The trick is to make all three boxes look like a single box (and the secret is... make a 4th box larger than the three single boxes and have the 4th box encase the three boxes - and remember to turn the 4th box's collision off. No one ever needs to know the one paddle is actually 4 seperate paddles working together.
Somthing like this: [[B1][B2][B3]]

You could also use some simple math instead. Just get the X coordinate of the ball and the X coordinate of the paddle (Use; Object Position X() ). Then calculate about 1/3 your paddle size (or whatever feels right). Then subract half that distance for the left side and add half that distance for the right side. For example: Paddle Size = 30. 30/3 = 10, and 10/2 = 5.
So Left would be If Object Position X(Ball)<Object Position X(Paddle)-5
Right would be If Object Position X(Ball)>Object Position X(Paddle)+5
Any remamining collisions by default would be the center.

One last method would be a smoother method and the angles would all depend on where your Ball hit on the paddle.
When a collsion is detected, move the ball using something like:
Position Object Ball#, Object Position X(Ball#),Object Position Y(Ball#), Object Position Z(Paddle#)+5
(in place of "+5" use an offset that is 1/2 your Paddle's Z size)
Then point the ball at the paddle's center:
Point Object Ball#,Object Position X(Paddle#),Object Position Y(Ball#),Object Position Z(Paddle#)
Then turn the ball around 180 degrees.
Turn Object Left Ball#,180
Then send the ball off on it's merry way. The ball is heading directly away from the paddle's center, so, the more offset the ball hits the paddle, the more of an angle the ball will leave at.

Any of these will work just fine. Hope this helps.

Edit: When I wrote this, I was thinking a horizontal paddle along the X-axis hitting a ball traveling primarily along the Z-axis. It occurs to me now, that's more like breakout instead of pong, but the concepts are the same.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Johnny Bolt
19
Years of Service
User Offline
Joined: 30th Dec 2004
Location: South Jersey
Posted: 12th Feb 2005 02:20
Yes that helps alot. I was actually just sitting down to try the first one on my own when I though about checking this thread. Nice to see that I am thinking along the right lines.

Your second idea, I hadn't thought of but make sense.

Your third suggestion is kind of what I was thinking all along, just wasn't quite sure how to make it work. I'm still a little fuzzy on how to make it work but it's a good start and I am going to sit later and work out all three to see which I like working with better.

I'll do this because when I work these kinds of things out, I try to document them well and then store the info for later use in other projects. I have enough little bits of code you could choke a paper sheredder with. Thank God for the digital age. It only eats up drive space.

Thanks for your help and will let you know how I make out.

The only true failure is not to try at all...
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 12th Feb 2005 08:05
Johnny, here's an example of the 3rd method:
Warning: Spoiler!



"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Johnny Bolt
19
Years of Service
User Offline
Joined: 30th Dec 2004
Location: South Jersey
Posted: 14th Feb 2005 13:03
Finally decided on a way to get the ball to move the way I want.

I tried the first and the third and didn't really like the way either turned out. I liked the way my current setup works moving the ball and collision, just couldn't get either to work well with my current code. The third way I pretty much had to re-write the entire program. Didn't really want to spend that much time but figured I needed to make sure it wasn't going to work.

Figured that the best attack was your second idea. Since most of the current program moved the ball using the x,y,z... this would be very easy to accomplish. I've pretty much worked the formula of how I want the ball to react just need to write the actual code to make it do it now. Shouldn't take long. Will post again when I have it completed. Should be in a day or two.

The program is coming along nicer then I thought and may actually be worth playing when I'm done. Have a few other idea's that will need help working out. But I don't want to get too far ahead of myself.

Thanks for all your help!

The only true failure is not to try at all...
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th Feb 2005 17:02
Welcome Johnny. I'll keep an eye on this thread regularly.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Johnny Bolt
19
Years of Service
User Offline
Joined: 30th Dec 2004
Location: South Jersey
Posted: 15th Feb 2005 11:31 Edited at: 17th Feb 2005 10:58
Got this little game working the way I want. May have been an easier way but I was never one for taking the easy way out. I guess once I get something in my head I stick to it. I'm sure most of your code snippets have only taken you a few minutes to write where I spend hours, but I'm sure the more I write the better I'll become. Ah the pains of being a novice.

I've included a link to a Zip file with the all the media and source files if anyone wants to take a look.

Let me know what you think.

http://home.comcast.net/~johnnybolt/3D_Pong_Game.zip

I've included the source code here without media. Use your own or download the zip file above.



The only true failure is not to try at all...

Login to post a reply

Server time is: 2024-11-27 22:42:18
Your offset time is: 2024-11-27 22:42:18