Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  Realistic ball movement  (Read 938 times)
0 Members and 1 Guest are viewing this topic.
Offline Bassex96

Senior Member


Medals: 4



« Posted 2013-04-24 03:51:36 »

How would I go about implementing realistic ball movement in my brickbreaker game? I can't find anything on google that makes sense. Right now, the ball moves in four directions, NW,NE,SE,SW. It's basically always moving at a 45 degree angle. I want it to move around and bounce off objects realistically. I'm not sure where to start..
Offline HeroesGraveDev

JGO Kernel


Medals: 239
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-04-24 03:53:09 »

Something to do with the normals of the surface it bounces off.

Not sure of the formula, but I think it involves vectors & dot products.

EDIT: Just saw it is always moving at 45 degree angle.

1  
2  
3  
4  
5  
6  
7  
8  
if(collidesOnXAxisMovement())
{
    velocity.x = -velocity.x;
}
if(collidesOnYAxieMovement())
{
    velocity.y = -velocity.y;
}

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-04-24 04:02:23 »

HeroesGraveDev's version will work, also check this out.
I really think you should use google/your own brain a bit more, though...this is a problem easily solved just by thinking, and even if that fails you can always search.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Agro
« Reply #3 - Posted 2013-04-24 04:05:58 »

Well, you're going to have to implement velocity, accelaration, deceleration, bounce, etc etc.

Offline Bassex96

Senior Member


Medals: 4



« Reply #4 - Posted 2013-04-24 04:06:26 »

HeroesGraveDev's version will work, also check this out.
I really think you should use google/your own brain a bit more, though...this is a problem easily solved just by thinking, and even if that fails you can always search.

I've already got a full system implemented. The ball moves, bounces, collides, all that. I just don't like the way it moves. I've been racking my brain over this for a few days now and the only thing i've been able to come up with is detecting the degree of the angle before it hits a wall and compensating..I just haven't been able to figure out how to put this into code yet.

Believe me, i've been searching and thinking about this. I try not to ask anything here until i've fully researched it...Maybe i'm just researching it wrong, but like I said, I couldn't find what I was looking for. His solution above, doesn't even have anything to do with what i'm asking...But thank you.
Offline Bassex96

Senior Member


Medals: 4



« Reply #5 - Posted 2013-04-24 04:07:53 »

Well, you're going to have to implement velocity, accelaration, deceleration, bounce, etc etc.

Yeah, i'm working on the velocity/deceleration already. That isn't too much of a problem. Right now, the ball moves by -1 or 1 on the X and Y axis. That's the problem.
Offline Bassex96

Senior Member


Medals: 4



« Reply #6 - Posted 2013-04-24 04:11:37 »

HeroesGraveDev's version will work, also check this out.
I really think you should use google/your own brain a bit more, though...this is a problem easily solved just by thinking, and even if that fails you can always search.

You're awesome. That link was what I was looking for. Thank you.
Offline Roquen
« Reply #7 - Posted 2013-04-24 12:20:04 »

An arbitrary bounce is a reflection about the normal of the surface.  The parallel part is negated and the orthogonal part remains the same (assuming idealized interaction...no friction, idealized surfaces, etc).
Online relminator
« Reply #8 - Posted 2013-04-24 12:30:27 »

Old article I wrote:

http://petesqbsite.com/sections/express/issue21/index.html#bounce

There's also a link there for an even older Ball to ball collision and response.
Offline Roquen
« Reply #9 - Posted 2013-04-24 12:55:49 »

I stuck a mini write-up at the bottom of this: http://www.java-gaming.org/topics/complex-number-cookbook/28991/msg/264958/view.html
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Axeman

Senior Member


Medals: 7



« Reply #10 - Posted 2013-04-24 21:14:08 »

Yeah, i'm working on the velocity/deceleration already. That isn't too much of a problem. Right now, the ball moves by -1 or 1 on the X and Y axis. That's the problem.

If you´ve come to the point that you want realistic movement it´s time to start learning vector math. If you used vectors you could get what is called "reflection vector" which will give you a more realistic behaviour. Here´s a link to a nice tutorial (not java code but a pretty nice description of the idea):

http://www.wildbunny.co.uk/blog/2011/04/06/physics-engines-for-dummies/

It requires that you know your way around vectors though...
Offline Bassex96

Senior Member


Medals: 4



« Reply #11 - Posted 2013-04-24 22:20:38 »

You guys are great. I've been pouring over the article Jimmt posted and it's great but a little overwhelming. I'm going to check all of these resources out and get it implemented. I can't wait to finish this game so I can start on something else. I'm going to change the levels to use Tiled so I can get some experience for my 2d tiled game. I think i'm going to also add some lights using box2dlights. That should be about it. It's about finished. Everything else works great.
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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (25 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

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

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!