Here is another MATHLESS method of doing it.
Code with everything commented
set display mode 1280, 1024, 32
`No user input shows the construct rotating
`Clicking and Holding Mouse 1 will show a cube orbiting around a point
`Clicking Mouse 2 changes which axis you are rotating on
`Mousewheel changes the radius/distance of the orbit
`Advantages of this method:
`NO MATH
`Easy to implement and use for various effect
`Basically anywhere where you want to orbit/rotate
`something in 3d space.
`You can add more than one limb, for multiple orbit points
`Around the same point. The points will be relative to
`each other
`This builds our basic construct for our mathless rotation
make object sphere 1, .2
make mesh from object 1,1
add limb 1, 1, 1
delete mesh 1
offset limb 1,1, 0, 0, 1 ` This is our radius/distance depending on what you are trying to do
make object cube 2, .2
hide object 2
mousez() = 1000
do
` These are the two most important functions for this method
` This positions the object at the orbit point. NOTE: You can position other things like
` Lights, and Cameras at this position to.
position object 2, limb position x(1,1), limb position y(1,1), limb position z(1,1)
`This is just our radius/distance from whatever we are orbiting around. Be it a point
`in 3d space, or the player itself.
offset limb 1,1, 0, 0, mz# / 1000
`For a chase camera. Position Object 1 at the XYZ of your character. Then position the
`Camera at the XYZ of the LIMB. Then point the camera at the XYZ of your character.
`When you rotated your character rotate object one with the same values. Or for neat
`Effect rotate the camera faster or slower.
`You can always reposition the camera to be directly behind the character you are following
`by setting Object 1 rotate values to be equal to your characters rotation values.
`ALL of this code just showcases the method
`Use the Mousewheel to set radius/distance
mz# = mousez()
`Rotate around the X axis
if ra = 0
a# = a# + .02
xrotate object 1, a#
endif
`Rotate around the y axis
if ra = 1
b# = b# + .02
yrotate object 1, b#
endif
`Rotate around the Z axis
if ra = 2
c# = c# + .02
zrotate object 1, c#
endif
`Reset everything to fault visually
if mouseclick() = 0
mc = 0
show object 1
hide object 2
endif
`Show Cube Orbiting around the point
if mouseclick() = 1
hide object 1
show object 2
endif
`Change axis rotation
if mouseclick() = 2 and mc = 0
mc = 1
ra = ra + 1
if ra = 3 then ra = 0
endif
loop
if spacekey() = 0
text 0, 0, "Press Space to show Quick Help"
endif
if spacekey() = 1
text 0,0 , "Mouse 1: Show Cube Rotating"
text 0, 12, "Mouse 2: Change Rotation Axis"
text 0, 24, "Mouse Wheel: Change Radius/Distance"
endif
Code SANS comments
set display mode 1280, 1024, 32
make object sphere 1, .2
make mesh from object 1,1
add limb 1, 1, 1
delete mesh 1
offset limb 1,1, 0, 0, 1
make object cube 2, .2
hide object 2
mousez() = 10000
do
position object 2, limb position x(1,1), limb position y(1,1), limb position z(1,1)
offset limb 1,1, 0, 0, mz# / 1000
mz# = mousez()
if ra = 0
a# = a# + .02
xrotate object 1, a#
endif
if ra = 1
b# = b# + .02
yrotate object 1, b#
endif
if ra = 2
c# = c# + .02
zrotate object 1, c#
endif
if mouseclick() = 0
mc = 0
show object 1
hide object 2
endif
if mouseclick() = 1
hide object 1
show object 2
endif
if mouseclick() = 2 and mc = 0
mc = 1
ra = ra + 1
if ra = 3 then ra = 0
endif
if spacekey() = 0
text 0, 0, "Press Space to show Quick Help"
endif
if spacekey() = 1
text 0,0 , "Mouse 1: Show Cube Rotating"
text 0, 12, "Mouse 2: Change Rotation Axis"
text 0, 24, "Mouse Wheel: Change Radius/Distance"
endif
loop