Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (582) Games in Android Showcase (163) games submitted by our members Games in WIP (632) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 a "pass" funktion in a ball game? looks bad.  (Read 1057 times) 0 Members and 1 Guest are viewing this topic.
VeNOM

Senior Newbie

[ G.O.A.T ] 4 life

 « Posted 2003-03-05 20:02:32 »

Hi
Im doing a ball game and is working on the pass and shoot funktions.
Right now im doing so that i have the ball x and y and while the ball hasent intesected with a player it moves 3 pixels in the dir towards the player. 3 pixels in x and 3 in y until the ball have the same x and y as the player.
The problem is that this dont look nice at all.. the ball is moving werry bad.

I was woundering if anyone have a better idea in how to make this look better and natural.
I have been thinking about using pytagoras mathematics to calculate the length of the hypotenusa(i spell bad i know ) and by that somehowe make the ball go 3 pixels on that line.. but the problem is in how to calculate the x and y to the endpoint..

But someone may have a mutch better sulution..
Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

 « Reply #1 - Posted 2003-03-05 22:04:01 »

If you keep moving the ball towards the player, you're going to get a homing pass that will kinda take all the skill out of the game

Heres how i'd probably go about things:
1. At the start of the pass, find the direction the ball should travel in (probably due to start and target relative positions).

2. Per update, if not hit the player, then move along the direction vector.

 1  2  3  4  5  6  7  8  9  10  11  12 `// At start of throw:float dx = target.x - start.x;float dy = target.y - start.y;// Normalise the direction vectorfloat length = Math.sqrt( dx*dx + dy*dy );dx = dx / length;dy = dy / length;// Per update:ballX += dx * speed * timeDelta;ballY += dy * speed * timeDelta;`

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Ralphanese (17 views) 2015-05-28 16:52:52 theagentd (31 views) 2015-05-27 22:21:17 theagentd (35 views) 2015-05-27 22:21:08 CopyableCougar4 (25 views) 2015-05-27 19:24:50 MrMapcom (24 views) 2015-05-23 20:26:16 MrMapcom (32 views) 2015-05-23 20:23:34 Waterwolf (37 views) 2015-05-20 15:01:45 chrislo27 (44 views) 2015-05-20 03:42:21 BurntPizza (79 views) 2015-05-10 15:53:18 FrozenShade (64 views) 2015-05-07 09:11:21
 Rayvolution 24x theagentd 19x Spasi 19x Riven 18x BurntPizza 16x Drenius 15x ra4king 13x opiop65 12x EgonOlsen 12x princec 12x orangepascal 12x DavidBVal 11x Husk 11x KevinWorkman 10x kevglass 9x scanevaro 8x
 List of Learning Resources2015-05-05 10:20:32How 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:00
 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