Ball Object 3d Rotation
#1

I made a Pool Script and I move balls' position with this code (done every 20ms):
Код:
GetObjectPos(PoolBall[i][bObject], x1, y1, z);
x1 += ((PoolBall[i][bSpeed]/50) * floatsin(-a, degrees));
y1 += ((PoolBall[i][bSpeed]/50) * floatcos(-a, degrees));
SetObjectPos(PoolBall[i][bObject], x1, y1, z);
That's a small code that works perfectly, but I have a problem with ball rotation (that with SetObjectRot). Here's how I did it:
Код:
GetObjectRot(PoolBall[i][bObject], rx, ry, rz);
rx -= ((20.0 * PoolBall[i][bSpeed]) * floatcos(-a, degrees));
ry += ((20.0 * PoolBall[i][bSpeed]) * floatsin(-a, degrees));
SetObjectRot(PoolBall[i][bObject], rx, ry, rz);
So I realized that this isn't the right way to rotate a ball..

Who can tell me the right algorithm to rotate a ball that's moving, knowing the angle of direction and the moving's speed?

PS: Note that "a" is the angle of ball's direction.
Reply
#2

I think you did it right, can't find errors :/
Reply
#3

Quote:
Originally Posted by Derbyan
Посмотреть сообщение
I think you did it right, can't find errors :/
The error is that I don't use the right algorithm...
Reply
#4

Pretty pointless using the trigonometrical functions, I mean you can do it another way:

pawn Код:
GetObjectRot(PoolBall[i][bObject], rx, ry, rz);
rx -= 0.3;
ry += 0.3;
SetObjectRot(PoolBall[i][bObject], rx, ry, rz);
Should spin nice since you've got a 20 ms timer, though isn't necessary, 50 - 75 is good enough..
Reply
#5

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Pretty pointless using the trigonometrical functions, I mean you can do it another way:

pawn Код:
GetObjectRot(PoolBall[i][bObject], rx, ry, rz);
rx -= 0.3;
ry += 0.3;
SetObjectRot(PoolBall[i][bObject], rx, ry, rz);
Should spin nice since you've got a 20 ms timer, though isn't necessary, 50 - 75 is good enough..
This way is wrong, because it doesn't consider the direction angle (a).
Reply
#6

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Pretty pointless using the trigonometrical functions, I mean you can do it another way:

pawn Код:
GetObjectRot(PoolBall[i][bObject], rx, ry, rz);
rx -= 0.3;
ry += 0.3;
SetObjectRot(PoolBall[i][bObject], rx, ry, rz);
Should spin nice since you've got a 20 ms timer, though isn't necessary, 50 - 75 is good enough..
He wanted to do a realistic movement Lorenc.
The problem is setting the rotation based on the direction of the pool ball.
Reply
#7

No one can help me?
Reply
#8

UP

___
Reply
#9

UP.. After a month D:
Reply
#10

Should be some complex math involved. Try googling it. All I could find were algorithms for ball collision. I know it can be done though, some guy made a video of it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)