Hi again, i have another problem i'm unable to solve do to my bad understandings how exactly limbs work.Here is some sample code i ripped out of my rubik's game to be...It works just i want it to but there is something strange happening when rotation ocures.If you look at positions you will see that when you rotate cubes some positions deviate from originaly inteded. Example: If you hover the mouse on object 9 it shows x:0 , y:0 ,z:0.When you rotate counterclockwise object 7 goes where 9 was but "y" says 2.185... though the object is at the right place the limb goes not where i expect it to be.And this is a problem because i use plains just like in this example for every side of the cube to group cubes and if a limb offsets like this, sometimes it goes in wrong group and cube start rotating randomly> Sometimes program crash if some random cube goes in a group array and overload it because the arrays are designed to hold 9 cubes at any given time in a group, but suddenly they become 10 or more.I can't figure out some workarround for this.
Here is the code:
sync on : sync rate 30
type cube
ID as integer
VerticalAssignment as byte
HorizontalAssignment as byte
Frame
Radius#
endtype
dim Cubes(9) as cube
for i = 1 to 9
make object cube i,4.9
Cubes(i).ID = i
next i
for i = 6 to 9
Cubes(i).Frame = i*90
next i
Cubes(2).Frame = 45
Cubes(3).Frame = 135
Cubes(4).Frame = 225
Cubes(5).Frame = 315
offset limb 1,0,0,0,0
offset limb 2,0,-5,0,-5
offset limb 3,0,5,0,5
offset limb 4,0,-5,0,5
offset limb 5,0,5,0,-5
offset limb 6,0,5,0,0
offset limb 7,0,-5,0,0
offset limb 8,0,0,0,5
offset limb 9,0,0,0,-5
make object plain 16,16,16
offset limb 16,0,0,0,0
`position object 16,0,0,0
rotate object 16,90,0,0
position camera 0,10,-30
do
text 0,0,"selected object: "+str$(selected_object)
text 0,20,"old selected object: "+str$(old_selected_object)
text 0,40,"hovered object: "+str$(hovered_object)
text 0,60,"frame: "+str$(frame)
text 0,80,"newmsx: "+str$(newmsx)
text 0,100,"newmsy: "+str$(newmsy)
if hovered_object > 0
text 0,120,"limb position x: " + str$(limb position x(hovered_object,0)) + "y: " + str$(limb position y(hovered_object,0)) + "z: " + str$(limb position y(hovered_object,0))
else
text 0,120,"Object position x: null " + "y: null " + "z: null"
endif
if mouseclick() = 1
selected_object = pick object (mousex(),mousey(),1,70)
endif
hovered_object = pick object (mousex(),mousey(),1,70)
if mouseclick() = 1
if ms_update = 0
ms_update = 1
oldmsx = mousex()
oldmsy = mousey()
old_selected_object = selected_object
endif
endif
if mouseclick() = 0 then ms_update = 0
newmsx = mousex() - oldmsx
newmsy = mousey() - oldmsy
if mouseclick() = 1
if rotation = 0
clicked = 1
rotation = 1
endif
endif
if mouseclick()= 0
if rotation = 1
for i = 1 to 9
if limb collision (16,0,i,0) and old_selected_object = i
selected_object = old_selected_object
if newmsx => 0 and frame < 9
inc frame
for n = 1 to 9
`Counter clockwise rotation
yrotate object n,object angle y(n)-10
next n
endif
if newmsx <= 0 and frame >-9
dec frame
for n = 1 to 9
`Clockwise rotation
yrotate object n,object angle y(n)+10
next n
endif
endif
next i
endif
endif
if frame = 9 or frame = -9
clicked = 0
rotation = 0
endif
if clicked = 0 then frame = 0
sync
loop
Coding is My Kung Fu!
And My Kung Fu is better than Yours!