Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Bouncing Ball - Physics and Collision Detection  (Read 4812 times)
0 Members and 1 Guest are viewing this topic.
Offline submitter

Senior Newbie





« Posted 2007-03-26 19:54:46 »

Hey, I'm pretty new to Java3D and what I want to do is have the ability for a player in my 3D FPS game be able to throw a ball at a given angle and given speed and then for the ball to bounce realistically off of the ground and the walls and eventually come to a stop.

I have no idea where to begin with this but I know I'm going to need some physics and collision detection in there.

Does anyone have any resources I could refer to for help with carrying out this task? Perhaps you know someone who has done it before with a guide on a website somewhere? I've tried googling but havn't really found much useful.

Many thanks.
Offline t_larkworthy

Senior Duke


Medals: 1
Projects: 1


Google App Engine Rocks!


« Reply #1 - Posted 2007-03-27 02:00:39 »

You could try JOODE, it does all that kinda stuff for you. Docs a bit flimsy but it works the same as ODE (which has better documentation), plenty of test cases though in the repository. I could do with a user to force me to write some tutorials  Undecided  Have a look at the game physics forum.

Runesketch: an Online CCG built on Google App Engine where players draw their cards and trade. Fight, draw or trade yourself to success.
Offline submitter

Senior Newbie





« Reply #2 - Posted 2007-03-27 14:25:55 »

OK I think this might be more complicated than I initially thought, so I've decided to start with a simple ball bouncing up and down in the center of the scene.

Putting the physics to one side for a moment, what would be the best way to animate such a bouncing ball? The first method that comes to mind is to simply calculate the ball's position every 5ms (say) based on the principles of physics in such a scenario (in this case mainly gravity), and every 5ms draw the ball in its new position. I don't really know much about animation in Java3D at the moment so would this be an OK method? If not, what better methods are there?

Thanks Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline submitter

Senior Newbie





« Reply #3 - Posted 2007-03-27 19:20:24 »

After reading the Sun Java3D Tutorials (and kind of understanding) I think I have to use behaviors? Do I need to create my own behavior or can I use PositionInterpolator?

There doesn't seem to be much documentation about this anywhere on the Internet. I've not had any luck in finding much anyway.
Offline gideon

Senior Newbie





« Reply #4 - Posted 2007-03-27 20:12:20 »

The 'animation' of a moving ball is usually (if not always) done by calcuting the ball's new position every frame and drawing it at the appropriate position. I don't know anything about Java3D, but I'm pretty sure you wouldn't need anything special like a PositionInterpolator that you mentioned.

Judging from your questions, you seem quite new to game programming in general (please forgive me if I'm wrong). Might I suggest to start with simple 2D games first? Implementing a small packman game would teach you most of the basics you'd also need for 3D and can be done in less than a week's time. Any 3d shooter would certainly cost you months or more likely years to finish, depending on how much you start with.

You'd be suprised how incredibly complicated physics-systems can be, something like ODE (or the java port/rewrite JOODE) cost a number of people a few years to write. I'm not trying to discourage you though, but in this case it might be more educational and rewarding to start small.

The towship's adventures
Offline submitter

Senior Newbie





« Reply #5 - Posted 2007-03-27 20:49:01 »

Thanks for your reply gideon.

You're right when you say I'm new to game programming! Unfortunately I don't have the time to study 2D game programming as I'm doing this work as part of a project at university (with the deadline approaching quicker than I would like Undecided)

I understand the basic principle you have described for creating a simple falling ball but I can't figure out how to animate this in Java3D. Please see Code for Episode 1 at the following link:

http://wiki.showmedo.com/index.php/PythonThompsonVPythonSeries

Here a falling ball has been implemented (quite simply and painlessly) using VPython.

Calculating the position of the ball every 5ms (say) is trivial; what I can't figure out is how to display the ball in the scene every 5ms.

I am still researching and it seems I may have to use a custom made Behavior class using the WakeupOnTimeElapsed wakeup criteria. Can anyone confirm if this is what is needed?

Thanks for the help Smiley
Offline submitter

Senior Newbie





« Reply #6 - Posted 2007-03-27 22:47:58 »

Finally got it working  Grin (ball falling to the ground)

I had to create my own Behavior class; pretty simple once you know how, doh!

Now I can start to think about having the ball fall from the sky and bounce in 1 dimension (Y-axis) to a stop. This of course means thinking about collision detection.

I noticed one of the wakeup criteria is WakeupOnCollisionEntry - does anyone know if this can be used in this situation? So that the ball would fall and once it detected a collision with the ground the falling (downward) behavior would halt and the new upward behavior would begin...

Cheers
Offline tom
« Reply #7 - Posted 2007-03-28 18:12:14 »

Use WakeupOnElapsedFrames(0) to run flat out and get a callback every frame. Use System.currentTimeMillis or System.nanoSomething to calculate the elapsed time between frames. Use this time with the physics. Ball position can be calculated as
1  
2  
3  
newBallx = oldBallx + velocity.x * time
newBally = oldBally + velocity.y * time
newBally = oldBally + velocity.y * time


Don't think you can use WakeupOnCollisionEntry since you want to detect collision before collision. You can use the picking package for collision detection. Although any real collision detection would be complicated for a newbie.

For a simple bouncing ball you could just check the bally and set velocity sign.
1  
2  
if ballx < 0
   ball.vely = -Math.abs(ball.vely)

Offline Conzar

Junior Duke




There is nothing common about common sense


« Reply #8 - Posted 2007-04-11 16:39:10 »

Well, I wouldn't say that collision detection is necessarily too complicated for a NOB depending on their mathmatical knowledge (for instance, 3 variable calculus is much more complex then collision detection).  Anyways, here is a good site that goes through how collision detection and avoidance works in java 3d

http://java3d.j3d.org/tutorials/collision/index.html

Also, this site http://www.j3d.org has other great tutorials to get you up and going in java 3d.

Ubuntu
Offline submitter

Senior Newbie





« Reply #9 - Posted 2007-04-25 17:19:13 »

Thanks for the help guys, muchly appreciated. Collisions are now working very well Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline keldon85

Senior Duke


Medals: 1



« Reply #10 - Posted 2007-05-31 07:32:08 »

Oh gosh, with moving balls you use basic vector maths. You do not check every frame, it's just not the "proper" way to do it ... you basically rotate the line by the movement vector (using the UVN rotation system, then it's all easy from there. Check if the point of collision is within the movement of the circle - this will check to see if the circle moved through the line.

Then transform your line into a fat line, the circles into points, and do a simple check to see whether the points are within the fat line; so pm me if I don't provide you with a solution within 36 hours of this post.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (33 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (74 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!