Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (683) Games in Android Showcase (196) games submitted by our members Games in WIP (751) 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 1926 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: 381
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: 167
Projects: 5
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.

 orrenravid (210 views) 2016-07-16 03:57:23 theagentd (281 views) 2016-07-11 14:28:54 Hydroque (366 views) 2016-07-06 05:56:57 Hydroque (519 views) 2016-07-03 08:52:54 GrandCastle (392 views) 2016-07-01 09:13:47 GrandCastle (385 views) 2016-07-01 09:09:45 CopyableCougar4 (437 views) 2016-06-25 16:56:52 Hydroque (413 views) 2016-06-22 02:17:53 SwampChicken (379 views) 2016-06-20 13:22:57 SwampChicken (303 views) 2016-06-20 13:22:49
 Archive 30x Brynn 23x Slyth2727 23x TritonDreyja 22x EgonOlsen 22x orangepascal 22x orange451 20x DavidBVal 19x Spasi 18x KaiHH 12x LiquidNitrogen 11x Phased 11x Opiop 11x princec 11x Longor1996 10x theagentd 10x
 Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17
 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