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 / How do I make an Obect Spin?

Author
Message
Bloder
17
Years of Service
User Offline
Joined: 24th Feb 2007
Location: Cyberspace
Posted: 20th Feb 2010 22:20
Hi, I was wondering, how do you make an object spin along one of its axis?

If I were you, I'd make a game...
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 20th Feb 2010 23:28 Edited at: 21st Feb 2010 20:22
Here you go:



Press 'X' to spin on the X axis, 'Y' to spin on the Y axis or 'Z' to spin on the Z axis. You can press all three at one time if you want.

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 21st Feb 2010 00:15
Alternatively, you can use the TURN OBJECT RIGHT, TURN OBJECT LEFT, PITCH OBJECT UP, PITCH OBJECT DOWN, ROLL OBJECT LEFT, and ROLL OBJECT RIGHT commands.

These are designed more for free flight rotation and take the same arguments as the XROTATE OBJECT, YROTATE OBJECT, and ZROTATE OBJECT commands.

I will usually flip between the two methods depending on what I need them for, as I find that sometimes the free flight rotation commands don't work perfectly with other commands. The real benefit in my mind to them is it is a lot easier to read and interpret what they do rather than the ROTATE commands.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Feb 2010 02:59
You need a main loop:



And this line of code:

yrotate object 1,wrapvalue(object angle y(1)+2)

What it does is, it gets the objects current angle on axis y with object angle y(), it adds 2 to it, and so the command yrotate object doesn't throw an error when the angle is greater than 360, you put the addition into a wrapvalue() command, which wraps any larger numbers than 360 to a number within 0-360.

so:



TheComet

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Mar 2010 20:17
LBFN is back on the DBC Board!
Welcome home

@Bloder
One thing to aware of when rotating objects is that the axis of rotation is relative to the object, not the environment.

So if you start with an object that points forwards, its z axis points forwards, x axis running across, and y axis going up through the object. Now if you turn the object 90 degrees to the right, the z axis now points right and the x axis now points backwards.

On the second time you rotate the object you will get unexpected results unless you remember how the object is orientated.

There is however a command called FIX OBJECT PIVOT that lets you reset the axis of an object as if it were facing forwards, but leaving the object in its current orientation.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright

Login to post a reply

Server time is: 2024-04-26 06:48:36
Your offset time is: 2024-04-26 06:48:36