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
 Realistic ball movement  (Read 1008 times) 0 Members and 1 Guest are viewing this topic.
Bassex96

Senior Member

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: 253
Projects: 11
Exp: 2 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: 131
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 Member

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 Member

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 Member

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 Member

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 Member

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.

 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 (21 views) 2014-09-19 03:14:18 Dwinin (35 views) 2014-09-12 09:08:26 Norakomi (62 views) 2014-09-10 13:57:51 TehJavaDev (87 views) 2014-09-10 06:39:09 Tekkerue (42 views) 2014-09-09 02:24:56 mitcheeb (65 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 (40 views) 2014-09-07 01:11:22 Longarmx (36 views) 2014-09-07 01:10:19
 BurntPizza 37x Riven 18x princec 17x Rayvolution 17x ags1 16x basil_ 16x KevinWorkman 15x kevglass 12x theagentd 11x LiquidNitrogen 11x nsigma 11x HeroesGraveDev 9x The Lion King 7x deathpat 7x TehJavaDev 6x Gibbo3771 6x
 List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06List of Learning Resources2014-07-31 11:54:12HotSpot Optionsby dleskov2014-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