Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
Lapsa's very own thread
by rki. 06/19/24 11:27
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, degenerate_762), 1,213 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 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 | chip programmers | 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