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 / Rotating when moving...

Author
Message
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Sep 2005 12:39 Edited at: 23rd Sep 2005 12:41
I tried to pos this before, but then the thread turned into a convo about e-mails.. so I'll try again...

I can make my ball move around, and it slides around.. (I will post the code in a moment).. now, if you press the up key it will move along the z axis (for example). If you let go of the upkey, if will keep sliding in that direction, even if your facing another direction.. Now, what I want to do (and I need your help), it to make the ball always roll in the direction your going, not facing..

E.G.

if your moving along the z axis, and the ball if facing along the z axis, it shoul;d rotate round the X axis.
Say it keeps going in that direction, but you turn and face the X axis (moving along the z, facing x) the ball should then be x rotating....

I have no idea how to do this.. BUT, perhaps if I could get the angle between the direction im going, and direction im facing, maybe that would help, but I don't know...

Here's the imortant part of the code..




And a bit of code to find out how fast you're going to determine the speed to roll (already in the main part of the code)




Thanks to all those you can help (and I guess those who try)


TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Sep 2005 17:11 Edited at: 23rd Sep 2005 17:14
Hmmm... I love a challenge - and I'd never tried this before.

The trick is to calculate the amount of movement for the ball along the X and Z axis. This way, the actual position of the ball is independent of the ball's rotation.

Rather than calculate this real-time every time you rotate the object on the Y axis, (which would be slow), a procedure at the start of the program pre-calculates all the values for each of the 360 degrees of rotation and places them in arrays. This is done in CalcDirection.

You can then alter the ball's position using these arrays with the current Y angle of the ball as the array's index.

By rotating the ball on one angle - increasing for forwards and decreasing for backwards, all you need to do is make sure that the camera is behind the ball at all times. This is done with Set Camera To Follow.

Job done - but definitely a tricky one!

Nice challenge.



Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Sep 2005 17:19
this looks good, but it doesn't really help.. my ball slides around, and the problem is that i wanted to spin in the direction that its going, even if you turn the ball...


TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Sep 2005 17:26
That's what it does.

TDK_Man

Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Sep 2005 17:50
not really.. cos whenm you move you dont keep liding the way you do in my code, which means that if you turn to the side you go in the direction your facing, not the way you were going earlier


Leeorg
19
Years of Service
User Offline
Joined: 5th Jul 2005
Location:
Posted: 23rd Sep 2005 20:14
Are you saying that the ball stays travelling in any said direction but camera can swivel round the ball? so you are facing another direction but not going in that direction?
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Sep 2005 22:06
you can move, and it moves in that direction no matter which way you face.. but eventually the ball slows down. tyr the source code


TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Sep 2005 01:04
I didn't realise you'd posted working code - when you said:

Quote: "Here's the imortant part of the code.."


... I assumed it was only a section of the main program just for us to look at, so I didn't even try running it.

It wouldn't have mattered anyway - I just tried it and the code is DBP and doesn't run in classic. I tried it in DBP too but it didn't seem to be working in that either.

All I get is a white sphere on an empty blue backdrop. The sphere seems to rotate but doesn't do anything else.

TDK_Man

Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Sep 2005 03:23
aha, yeah. Just make a simple matrix so you can see yourself moving.. lol, and to make it work on dbc just take away the camera number


Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 24th Sep 2005 10:22
I'm making basically the same thing meself.

Here's how:



Hope that's what you wanted.

--------------
Uncle Sam
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Sep 2005 14:50
well it rolls around, but if you turn to the side, thats the way you go, its different with mine..


SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 25th Sep 2005 00:57
So you're after like an effect of a car (or in this case: ball) skidding - rather than just turning and moving perfectly in its new direction?

Well, I personally don't know how to do that, but perhaps others might (if that's even what you're after at all...)

...maybe one day I'll finish a project
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Sep 2005 02:06
No nonononono! I dont think anyone understands

Ok: have you ever went bowling? Well, say you drew a face on the bowling ball, and rolled it so its face would hit off the ground, it would rotate round the X axis.. but, turn it so the face is facing the arcade-section, it spins rounds its Z axis..

ok, so, say the bowling ball had a mind of its own.. it went towards the pins, but it didn't want to, it wanted to go into the gutter (which is what normally happens ), it will turn to face the side, but kepp rolling in the direction its going - towards the pins.. - now, say it starts to move forward.. it will move slightly on the x axis, and slightly on the Z axis.. so - which way does it roll? mostly round the X axis, and a little on the Z axis.. the faster it moves towards the gutter the faster it spins round the z axis (NOT the balls z axis)

This is what the ball does so far then -- moves fast towards the pins, and slowly towards the gutter.. how will it spin? - Alot round the Z axis (cos thats mainly the direction its going), and a little rouind the X axis. (cos thats also the way its going, just not as fast)

BUT, if the ball moves faster towards the gutter than it does the pins, then it will spin faster round its X axis rather than the Z axis - but it will still spin round the z axis a little 'cause its moving slightly in that direction

THIS is what I want to achieve, I hope I gave enough detail

thanks again


Login to post a reply

Server time is: 2025-05-22 12:45:13
Your offset time is: 2025-05-22 12:45:13