Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 12,709 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: 2D bouncing at an angle. [Re: Sepiantum] #298469
11/15/09 11:45
11/15/09 11:45
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
no, that won't work.

that advice is reminiscent of
http://www.opserver.de/ubb7/ubbthreads.p...true#Post255669

weird, how people throw useless help-balls at everyone.

Last edited by Joey; 11/15/09 11:48.
Re: 2D bouncing at an angle. [Re: Joey] #298894
11/18/09 20:28
11/18/09 20:28
Joined: Oct 2008
Posts: 67
C
Crypton Offline OP
Junior Member
Crypton  Offline OP
Junior Member
C

Joined: Oct 2008
Posts: 67
Okey, got it working!

Code:
var vVelocity[3]; //Ball speed vector!
var vBounce[3]; //Bounce vectro that gets copied to vVelocity

var a;

//normal vectors of edges
var nvec_minx[3] = {1, 0, 0 };
var nvec_maxx[3] = {-1, 0, 0 };
//=======================================================
         // b = 2*|<c,n>|*n + c  Bounce vector's formula.
         /*
         a = 2*abs(vec_dot(c, n));
         vec_set(c, vector(a*n[0], a*n[1],0));
         vec_add(c, c);
         */

//nvec_maxx = vec_normalize(nvec_maxx,1);
a = 2*abs(vec_dot(vVelocity, nvec_maxx));
vec_set(vBounce, vector(a*nvec_maxx[0], a*nvec_maxx[1],0));
vec_add(vVelocity, vBounce);



does basically all the magic and it works. The issue I had with the moving was that my previous vector had wrong values. Sometimes it had speed values and sometimes it had coordinates stored in it.

So I needed to have a vector that stores speed values only! And then changing panel's position according to it. So this is my solution.

Edit: Although I have seen now that when ball gets in some steep angle or smth it suddenly amplifies it's speed and does wierd stuff. So the calculation isn't always perfect though...
vec_bounce() dind't give the same result as rewritten formula...

Thanks Joey!

Last edited by Crypton; 11/18/09 20:32. Reason: after some test time

New into Gamestudio and eager to learn it..
Stuff and games done in 2D: LINK
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1