Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  modelling ball movement  (Read 4517 times)
0 Members and 1 Guest are viewing this topic.
Offline dupoli

Junior Newbie




Java games rock!


« Posted 2002-11-10 21:18:13 »

Hi,

I'm trying to write a crazy golf game and I'm not sure of the best approach to modelling the motion of the ball.

Has anyone got any suggestions/tips for this type of game ?

Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #1 - Posted 2002-11-21 12:15:00 »

So the big question is how your gonna do animation.  I am not an experianced J3D programmer so I don't think I am the best person to answere that question.  I will say, that in my current project, I have a control structure that will update anything that needs to be moved around the screen.  (or specific control structures for each group of things that need to be moved).

The question is how does that control structure make its decisions.  So maybe you should develop a physics class.  The class will take current input, given that input, it will develope a path for the ball with specific characteristics, like is the ball bouncing, rolling, sliding, ect.  The physics object will continually take input and continually modifies its plan.  

I hope this helps - maybe you already concidered this and were looking for more specific help?

Ubuntu
Offline dupoli

Junior Newbie




Java games rock!


« Reply #2 - Posted 2002-11-21 17:12:40 »

Thanks,

It sounds like I'm approaching it in a similer way to what you're suggesting. The things that I'm not too sure about are :

1) What is the best way to drive the animation ? My current approach it to use a thread to update the underlying model object (ball motion etc) and then refresh the screen. I call this the pull method.
Another way I could get it to work is to have the model object running as a thread and every time the ball moves a significant amount, get the model object to update the screen. I call this the push method. What other apporoaches are there ?


2) What is the best way to cope with the ball movement when velocity is very nearly 0 ? I have read a few articles mentioning the need dampening to prevent the ball doing odd things.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline leknor

Junior Member




ROCK!!!


« Reply #3 - Posted 2002-11-25 04:16:48 »

Browsing http://www.flipcode.com/links/ I found a link to: http://www.d6.com/users/checker/dynamics.htm where the author has archived 4 articles he has written about rigid body dynamics for Game Developer Magazine. He also has a 2d and 3d demo with source which may prove useful.
Offline dupoli

Junior Newbie




Java games rock!


« Reply #4 - Posted 2002-11-25 11:31:39 »

Thanks those articles are a great help
Offline zparticle

Senior Member




Thick As A Brick


« Reply #5 - Posted 2003-02-15 16:01:56 »

I'm trying to get the ball movement (angular/velocity changes upon collision) in a breakout type game working. It would seem that this should be an easy problem not requiring any fancy physics but I can't seem to get it right. Could someone either post a bit of code from their breakout game or read the following and help me get it right?

Specifically I am having problems with the ball not coming off of a collsion with a block in the correct manner so I end up with weird ball movement. This movement can cause a single horizontal row to be cleared by the ball becuase it never deflects enough to get outside of the row.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
    public void update(long currentTime) {
        super.update(currentTime);
        if(!lockedToPaddle)
        {
            if(posX<20)
            {
                posX=20;
                setXVelocity(-getXVelocity());
            }
            else if((posX+width)>(m.displayWidth-20))
            {
                posX=(m.displayWidth-20)-width;
                setXVelocity(-getXVelocity());
            }

            if(posY<=40)
            {
                posY=40;
                setYVelocity(-getYVelocity());
            }
            else if((posY+height)>m.displayHeight)
            {
                posY=(m.displayHeight-20)-height;
                lockedToPaddle=true;
            }
            else
            {
                if(hasCollided(m.player)) // ball hit the paddle
               {
                    setYVelocity(-getYVelocity());
                    float val = (getX()-m.player.getX()+getWidth())/m.player.getWidth();
                    if(val<.5f && getXVelocity()<0)
                        setXVelocity(getXVelocity()-(1f*val));
                    else if(val<.5f && getXVelocity()>=0)
                        setXVelocity(-getXVelocity()-(1f*val));
                    else
                        setXVelocity(getXVelocity()+(1f*val));
                    System.out.println(""+val);
                }
            }

            // detect block hits
           int pw = m.mapDisplay.cellBlock.cellPixelWidth;
            int ph = m.mapDisplay.cellBlock.cellPixelHeight;
            int startColumn = (int)((getX()-20)/(float)pw);
            int endColumn = (int)((getX()-20+getWidth())/(float)pw);
            int startRow = (int)((getY()-40)/(float)ph);
            int endRow = (int)((getY()-40+getHeight())/(float)ph);
            boolean top = false;
            boolean bottom = false;
            boolean left = false;
            boolean right = false;

            for(int row=startRow;row<=endRow;row++)
            {
                for(int col=startColumn;col<=endColumn;col++)
                {
                    MapCell cell = null;

                    cell = m.mapDisplay.cellBlock.getCell(col,row,0);
                    if(cell!=null &&
                       cell.fringeIcon>=0 &&
                       !m.mapDisplay.palette.getIcon(cell.fringeIcon).isFlagSet(MapTerrainIcon.FLAG_WALKABLE))
                    {
                        cell.fringeIcon = -1;
                        m.mapDisplay.changed=true;
                        m.soundHandler.playAudioClip(m.hitSound);

                        if(getYVelocity()<0 && !top) // moving up
                           bottom=true;
                        else if(getYVelocity()>0 && !bottom) // moving down
                           top=true;

                        if(getXVelocity()<0 && (!right && !bottom && !top)) // moving left
                           left=true;
                        else if(getXVelocity()>0 && (!left && !bottom && !top)) // moving right
                           right=true;
                    }
                }
            }
            if(bottom || top) setYVelocity(-getYVelocity());
            if(left || right) setXVelocity(-getXVelocity());
        }
    }

Offline BOUNCE

Junior Newbie




Java games rock!


« Reply #6 - Posted 2003-04-30 15:55:04 »

make the ball go up in  the air, and then have arrows, make it look like it is flying!!!!!! Smiley
Offline BOUNCE

Junior Newbie




Java games rock!


« Reply #7 - Posted 2003-04-30 15:55:54 »

Try that allrighty then!!!!!
Offline BOUNCE

Junior Newbie




Java games rock!


« Reply #8 - Posted 2003-04-30 15:57:19 »

I AM REALLY NICE AND FRIENDLY, SO SEND ME A MESSAGE!!!!!!!
Offline Themroc

Junior Member





« Reply #9 - Posted 2003-05-21 16:42:06 »

This reply will be no big help, but ... I currently have to model a rolling ball myself. In the end I bought a physics book and looked up all the stuff there (friction, collision etc.). I didn't understood everything and I didn't found all in there what I needed but I got me much further than trying to only program by the "looks good, then it is correct" approach.
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.

BurntPizza (19 views)
2014-09-19 03:14:18

Dwinin (34 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (84 views)
2014-09-10 06:39:09

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (64 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (39 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!