Gamestudio Links
Zorro Links
Newest Posts
Future of ZorroHFT
by TipmyPip. 11/16/25 13:52
COT Download with Quandl does not work
by Petra. 11/15/25 09:35
Training with the R bridge does not work
by Petra. 11/15/25 09:31
Zorro 2.70
by jcl. 11/15/25 08:43
Camera always moves upwards?
by NeoDumont. 11/14/25 16:32
brokerCommand PLOT_HLINE parameters
by M_D. 11/13/25 10:42
ZorroGPT
by TipmyPip. 11/10/25 11:04
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (AndrewAMD), 8,508 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
tritom, sheliepaley, Blueguy, blobplayintennis, someone2
19178 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