Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / 3D Object angle calculation for balls - help!

Author
Message
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Feb 2009 16:52
Hello everyone!

I am trying to make a program where you drop a ball at the top of the 3d object and it rolls down. Unfortunately, I am having problems...

First of all, here is my code:



You will need to download the attached file for the media and sparky's dll.

What my program does, is it gets the height of the ground on the left and right side of the ball, subtracts those values to get the difference, and uses ATANFULL() to calculate the tilt of the slope on the x axis. The same with the Z axis, I get the height in front and behind the ball, subtract and use ATANFULL() to calculate the tilt of the slope on the z axis.

Now, what I am having problems with, is to figure what Y angle the sphere has to point to move in the right direction. I thought of using ATANFULL(anglex#,anglez#), but am not sure if that is the correct way of doing that. If you download the file, you will see that the sphere just rolls in one direction, off the side of the level and never to be seen again.

I appreciate any help or input from anyone!

TheComet

Ah yeah, for those that download it, mouse to view, up and down key to zoom and space to re-spawn the ball.

Peachy, and the Chaos of the Gems

Attachments

Login to view attachments
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 24th Feb 2009 23:45
Well, my understanding of slope is that it's the rise/run or height divided by length or y2-y1/x2-x1 . So in your atan formulas, the height portion should be the first parameter to get the tilt:



could be



Also, since a positive x rotation is a pitch down and a negetive x rotation is a pitch up, you have to make sure that dif1# is a subtraction of the rear value - the front value:
y2=height at z-5 , y1=height at z+5
dif1#=y2-y1

And for z rotation it's right-left
y2=height at x+5 , y1=height at x-5

If you intend to "roll" sphere, you should use a pivot object that never gets rotated and either use a limb or a glued object as the rolling object. If you rotate the object itself, it's angles will all change and won't be the same as the slope calculations.

Quote: "Now, what I am having problems with, is to figure what Y angle the sphere has to point to move in the right direction"


You'll have to get the heights around the sphere based on what direction it is facing. That means find x and z using newxvalue and newzvalue and the objects y angle. Find the y heights. Always rotate the sphere towards the lowest y. The rate at which you rotate the sphere will add realism and that can be determined by the slope - don't need th the angle of the slope in this case. The higher the absolute value of the slope abs(y2-y1/x2-x1 or y2-y1/z2-z1) the faster the yrotation towards that lowest value. While you are rotating the sphere, you are repositioning it in the y direction it is facing. Use a height percentage and gravity and friction to determine the speed of forward movement.

Enjoy your day.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 6th Mar 2009 14:27
Thank you for answering Latch! (I didn't really expect anyone else )

I still don't quite understand the second thing to figure out how to rotate the ball in the right direction. If I rotate to the lowest point, (I assume you look at the height at the front, left, back and right), won't it just rotate either to 0°, 45°, 90°, 135°, 180°, 225°, 270°, 315°, and 345°?

I will not be "rolling" the ball, but I know about the glue object trick(got it from you in the first place). I'm not sure if you played super mario 64 on the Nintendo 64, but I want to make a slide just like in that game and with the same physics.

TheComet

Peachy, and the Chaos of the Gems

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Mar 2009 17:05
Here's a quick example of what I was basically talking about. However, for coding speeds sake I knocked it together using a matrix, and I didn't use slope. You still could use slope and it would give a better representation of how fast to make the sphere slide. I just compared the different heights and move the sphere to the lowest point based on whatever direction it is facing.

Quote: "(I assume you look at the height at the front, left, back and right), won't it just rotate either to 0°, 45°, 90°, 135°, 180°, 225°, 270°, 315°, and 345"
°

Nope because I'm figuring out tthe left right front and back based on the direction the sphere is facing so it's not always N S E and W. If I rotated in 45 degree increments, then I suppose it would be as you said.

The sphere slides without changing it's facing (y angle) . I change the y angle by steering with the mouse. The Sphere won't slide as long as you are moving it with the arrow keys.

Try out the example. It should give you an idea of what I am talking about. Again, I didn't use the slope, I just used what side was the lowest.



Enjoy your day.

Login to post a reply

Server time is: 2025-05-18 08:54:22
Your offset time is: 2025-05-18 08:54:22