Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (623) 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 1371 times) 0 Members and 1 Guest are viewing this topic.
Bassex96

Senior Devvie

Medals: 4

 « Posted 2013-04-24 01: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..
HeroesGraveDev

JGO Kernel

Medals: 354
Projects: 11
Exp: 3 years

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

 « Reply #1 - Posted 2013-04-24 01: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;}`

Jimmt
« League of Dukes »

JGO Kernel

Medals: 159
Projects: 4
Exp: 3 years

 « Reply #2 - Posted 2013-04-24 02: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!
Agro
 « Reply #3 - Posted 2013-04-24 02:05:58 »

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

Bassex96

Senior Devvie

Medals: 4

 « Reply #4 - Posted 2013-04-24 02: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.
Bassex96

Senior Devvie

Medals: 4

 « Reply #5 - Posted 2013-04-24 02: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.
Bassex96

Senior Devvie

Medals: 4

 « Reply #6 - Posted 2013-04-24 02: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.
Roquen
 « Reply #7 - Posted 2013-04-24 10: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).
relminator
 « Reply #8 - Posted 2013-04-24 10: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.
Roquen
 « Reply #9 - Posted 2013-04-24 10: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!
Axeman

Senior Devvie

Medals: 7

 « Reply #10 - Posted 2013-04-24 19: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...
Bassex96

Senior Devvie

Medals: 4

 « Reply #11 - Posted 2013-04-24 20: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.

 ClaasJG (11 views) 2015-04-27 13:36:51 BurntPizza (32 views) 2015-04-23 03:42:11 theagentd (35 views) 2015-04-22 16:23:07 Riven (50 views) 2015-04-16 10:48:47 Duke0200 (59 views) 2015-04-16 01:59:01 Fairy Tailz (42 views) 2015-04-14 20:13:12 Riven (45 views) 2015-04-12 21:36:37 bus hotdog (61 views) 2015-04-10 02:39:32 CopyableCougar4 (66 views) 2015-04-10 00:51:04 BurntPizza (71 views) 2015-04-06 22:06:58
 theagentd 23x BurntPizza 17x wessles 15x alwex 11x 65K 11x kingroka123 11x kevglass 8x Olo 7x Ecumene 7x ra4king 7x Rayvolution 7x Riven 7x chrislo27 7x Hanksha 7x KevinWorkman 6x Roquen 5x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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