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.

Code Snippets / Collision, bounce and spin routine

Author
Message
RaceGT
19
Years of Service
User Offline
Joined: 15th Aug 2005
Location:
Posted: 19th Nov 2005 08:13
Collision, bounce and spin routine:

Here is the continuation of my collision & bounce routine. Now it has spin along with bounces, and even the start of adding gravity. I've got it to this point before I really have to start getting into rolling and laying on a surface, which will get very difficult I'm sure. But since it's at this point I thought it must be a good framework to start with anyone's looking for this sort of thing. It does alot, and you get the benefit of having a few weeks' work already done for you. But like I said, for it to go any further which I'm planning to do, is much more to be done, but I thought it was a good enough start that someone could get something out of it.

This uses Sparky's DLL an EZRotate. If you don't have EZRotate, you can take out the EZro command, but the object won't spin correctly after a couple/few bounces. That's why I needed EZRotate. However, it still creates the spin results properly even if DB doesn't rotate correctly, and someone may be able to use that. I was trying to learn rotation matrices to try to overcome the problem...has anyone seen the equations for rotation matrices, and the understanding that goes into them? Yeah right. Though I'll say that my main problem was actually getting the formulae put into working equations...THAT is the really complicated part. Learning vector operations was tough enough, but that other stuff...whew. If there was working code for rotation matrices then that would make everyone's life a lot easier in this area, but that's when I found out that DB actually did handle the axes differently and that it was a known problem to rotate objects 'independently', and that EZRotate actually addressed these issues. But I thought since we had "Fix Object Pivot", doesn't that make the need for EZRotate obsolete, since we can reset the object's axis after turning it (the mesh), and be able to re-start the rotations from 0? I don't know, but apparently someone knew there was a need for what EZRotate does...I know it fixed this problem. I tried for 2 weeks to fix my code thinking it was wrong, since I'd see it work correctly for the first few bounces. Deceptive.

So, before I start to try to finish whatever this is going to be, I'll put this part up and see if anyone can use it. Suggestions for what you can do (in the code):

You can mess with the gravity or take it out completely. It's a bounce routine with no gravity to start with...

Try to get friction from previous spin to alter the direction of the object, and cause the object to lose energy on each bounce.

Any number of things that can be added...that's why its pretty open ended at this point and I wanted to put it up...have fun.

http://www.geocities.com/crmnlelmnt/

Attachments

Login to view attachments
RaceGT
19
Years of Service
User Offline
Joined: 15th Aug 2005
Location:
Posted: 19th Nov 2005 10:42
Some notes on keys:

Mouselook
Arrows to move camera left/right & up/down.
Mouse wheel to move forward
1 + Shift-1 : Front & back views
2 + Shift-2 : Top & Bottom views
3 + Shift-3 : Left & Right views

Press r to reset (empty)
Press p to pause. When it pauses, press another key to be able to move the camera while it's paused. Press [ to resume or exit pause.
Press w for slow-motion, and w again for normal speed.

Notes: Collision detection is not perfect. There is a section in the code where you can see that I've made 3 extra spheres that act as markers. You can see one of these spheres, the red one, that acts as collision detector, and another one, the white one, that shows where the ball is headed towards the bounce. This is extraneous information, but you can watch the little red ball positioned on the main ball, while it's paused. You can see this acts as a sort-of feeler for detecting collisions. But there is another section in the code hat is commented out where I'm placing the little marker balls according to the object's movement speed on each axis: the less speed on that axis, the less the small marker ball gets positioned to the main ball, or more speed, the marker gets positioned away from the main ball to indicate the relative speed on that axis. Well, remember that little feeler ball? All it only really needs is one other feeler to be able detect pretty much all collisions, depending on which direction the ball is moving. SO that's something that can be improved upon, which I'm planning. I don't think you can do collisions like this while inside objects so it might be useful

http://www.geocities.com/crmnlelmnt/
RaceGT
19
Years of Service
User Offline
Joined: 15th Aug 2005
Location:
Posted: 26th Nov 2005 11:05
Anyone get any use out of this? Making an object spin correctly off a bounce, and namely successive bounces, is not an easy task. Now, I have to credit Sparky's DLL and EZRotate for much of the credit, but I put it together seeing how useful it could be...don't tell me everyone has their own bounce/collision/spin routine laying around?



http://www.geocities.com/crmnlelmnt/
RaceGT
19
Years of Service
User Offline
Joined: 15th Aug 2005
Location:
Posted: 28th Nov 2005 06:04
Well since I put it out there, I guess I should show one thing it could be useful for... or at least the first thing I've done with it so far. I'd like to be able to call it a 'hitting simulation', but it's really more the framework for some game I'm trying to put together. You swing the bat with the mouse when the pitch is coming in, and (if you hit it), the ball flies in the direction of the hit. You ran rip one down line(s), or hit to the field, all depends on how the bat hits the ball. And likewise for grounders or pop-ups; getting under the ball will get it up in the air, or you can hit a line shot, or you can hit one that bounces right in front of the plate. The directions and flies are correct, but what I haven't put in too much of is subjective factors like swing strength or maybe even something like how well the swing is timed. It has a simple meter for swing strength in that it uses mouse speed (therefore swing speed) to determine the swing's strength, but much more needs to be done here to make it really fun. And I haven't even touched making different types of pitches yet. Right now it's one pitch for testing; right down the middle (maybe a little high) and only about 70mph. It's slow enough that you can try to time your swing to hit the ball. But that will be an extra fun part that I want to hold off on right now, because it will be fun designing pitches. I can change the spin and rotation of the ball too while designing them so I can make them 'look' like different pitches, not that it will affect their flight in any way, but I can play with the looks of diffferent pitches in how they spin, not to mention their flight paths.
It's already a ton of fun just to try to hit one out of the park. Right now it's in 'cheat mode' because I can position the bat anywhere I want, and set up for the same pitch every time. So I get it set up, and start taking swings. Hitting a high long one...watching it sail, seeing if it's going to clear. Then...it's off the wall. They fly for a long time (not too long though) and you can watch it to see if it's going to clear. It's been a little tough to get the gravity and speeds evened out so it looks right, but now it looks very good. They sail maybe a little bit slowly, but it's very close to right. It's good enough at least where I can say it's something I'll look at later if I even decide I want to change it. I like watching them sail, waiting to see if it's going to clear...
I just got all the park pieces cut up into the respective 'response' pieces, so now any ball you hit will register correctly on the scoreboard (hit, foul, fair, Home RUN!, etc.). Oh and the scoreboard is 'working' too, it's set up to show messages with images now. The sky moves over time with a skydome, and the ball has a cool fake shadow that works pretty well.

http://www.geocities.com/crmnlelmnt/

Attachments

Login to view attachments
RaceGT
19
Years of Service
User Offline
Joined: 15th Aug 2005
Location:
Posted: 29th Nov 2005 14:17
I just got my copy of EZR v3, so I'm off to see what it can do for me. Bravo for allowing people to get at least the basic version (THAT WORKS), and let them decide if they want to spend a little to get the latest version. At least if they decide they don't want or need the payed version, they can still have something that at least works.

http://www.geocities.com/crmnlelmnt/

Login to post a reply

Server time is: 2024-11-23 10:47:32
Your offset time is: 2024-11-23 10:47:32