i think this is working very fine.
i have my brain "frito" friet? burn?
i thing, your code is very good, i just i need look more to understand the logic... with my brain fresh tomorow.
this is your code, with 3d rotation, works very perfectly.
// Project: test521
// Created: 20-05-31
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "test521" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
ship = CreateObjectBox(30,16,180)
SetObjectColor(ship, 0, 0xff, 0, 0xff)
center = CreateObjectBox(1, 1, 1)
FixObjectToObject(center, ship)
plane = CreateObjectBox(10,5,20)
SetObjectColor(ship, 0xff, 0, 0, 0xff)
SetObjectPosition(plane, 0, 20, 0)
SetCameraPosition(1, 0,200, -300)
SetCameraLookAt(1, 0, 0, 0, 0)
mode as integer
#constant FLY 0
#constant STICK 1
px as float
py as float
pz as float
sx as integer = 1
sy as integer = 1
sz as integer = 1
fx as float
fy as float
fz as float
ox as float
oy as float
oz as float
ocean = CreateObjectPlane(10000,10000)
rotateobjectlocalx(ocean,-90)
setobjectcolor (ocean,100,130,240,200)
SetObjectTransparency(ocean,2)
do
if random(1,200) = 1
sx = random(0,2) - 1
sy = random(0,2) - 1
endif
inc px, sx
inc pz, sz
if abs(px) < 200
if abs(pz) < 200
SetObjectPosition(ship, px, GetObjectY(ship), pz)
RotateObjectLocalY(ship, random(0,1))
// agrega escora
escora# = sin(GetMilliseconds()*.04)*11
cabeceo# = cos((80+GetMilliseconds())*.05)*6
SetObjectRotation(ship,0,GetObjectWorldAngleY(ship),0)
rotateobjectlocalx(ship,cabeceo#)
rotateobjectlocalx(ship,escora#)
else
pz = 200 * pz / abs(pz)
sz = sz * -1
endif
else
px = 200 * px / abs(px)
sx = sx * -1
endif
select mode
case FLY
if GetRawKeyState(38)
MoveObjectLocalZ(plane, 5)
endif
if GetRawKeyState(39)
RotateObjectLocalY(plane,3)
endif
if GetRawKeyState(37)
RotateObjectLocalY(plane,-3)
endif
if GetRawKeyPressed(32)
//atach
ox = GetObjectX(ship)
oy = GetObjectY(ship)
oz = GetObjectZ(ship)
fx = -(GetObjectX(ship) - GetObjectX(plane))
fy = -(GetObjectY(ship) - GetObjectY(plane))
fz = -(GetObjectZ(ship) - GetObjectZ(plane))
RotateObjectLocalx(center, -GetObjectAnglex(ship))
RotateObjectLocalY(center, -GetObjectAngleY(ship))
RotateObjectLocalz(center, -GetObjectAnglez(ship))
SetObjectPosition(plane, fx, fy, fz)
//SetObjectPosition(ship, 0, 0, 0)
FixObjectToObject(plane, center)
SetObjectPosition(ship, ox, oy, oz)
mode = STICK
endif
endcase
case STICK
if GetRawKeyPressed(32)
ox = GetObjectWorldX(plane)
oy = GetObjectWorldY(plane)
oz = GetObjectWorldZ(plane)
FixObjectToObject(plane, 0)
SetObjectRotation(center, 0, 0, 0)
SetObjectPosition(plane, ox, oy, oz)
mode = FLY
endif
endcase
endselect
print("Arrows-Move plane, SPACEBAR-Fix/UnFix plane to ship")
Sync()
loop