Hi Vikingblade.
Maybe something here will come in handy.
EDIT: actually, if you already got it working then disregard.
if GetRawKeyState(81)
SetObject3DPhysicsAngularVelocity(playerShip,0,-1,0,50)
//SetObject3DPhysicsAngularVelocity(playerShip,0,-GetObjectAngleY(playerShip),0,50)
endif
if GetRawKeyState(69)
SetObject3DPhysicsAngularVelocity(playerShip,0,1,0,50)
// SetObject3DPhysicsAngularVelocity(playerShip,0,GetObjectAngleY(playerShip),0,50)
endif
I gave it a test by throwing it in an attract / repel demo I made a while ago.
It might need to be adjusted to work in space with the ship being at all kinds of angles.
// Project: 3D physics attract and repel forces
// Created: 23-12-17
// added physics rotate test
SetErrorMode(2)
width# = GetMaxDeviceWidth()
height# = GetMaxDeviceHeight()
SetWindowSize(width#,height#,1)
SetVirtualResolution(width#,height#)
SetSyncRate(30,0)
SetScissor(0,0,0,0)
UseNewDefaultFonts(1)
Create3DPhysicsWorld()
Set3DPhysicsGravity(0,-2,0)
//SetGenerateMipmaps(1)
SetSkyboxVisible(1)
SetSkyBoxHorizonColor(100,100,255)
SetSkyBoxSkyColor(100,100,255)
setprintsize(height#/30)
light1=1
CreatePointLight(light1,0,1000,0,10000,255,255,255)
SetPointLightMode(light1,1)
// xxxxxxxxxxxxxxxxxxxxxx terrain
ground=1000
createobjectplane(ground,1000,1000)
setobjectcolor(ground,40,100,40,255)
rotateobjectlocalX(ground,90)
Create3DPhysicsStaticBody(ground)
setobjectshapebox(ground)
SetObjectCollisionMode(ground,1)
SetObject3DPhysicsGroupAndMask(ground,1,2)
// xxxxxxxxxxxxxxxxxxxxxx walls
wall1=CreateObjectBox(800,150,5)
SetObjectposition(wall1,0,0,400)
setobjectcolor(wall1,random(50,200),random(50,200),random(50,200),255)
Create3DPhysicsStaticBody(wall1)
SetObject3DPhysicsGroupAndMask(wall1,1,2)
wall2=CreateObjectBox(800,150,5)
SetObjectposition(wall2,0,0,-400)
setobjectcolor(wall2,random(50,200),random(50,200),random(50,200),255)
Create3DPhysicsStaticBody(wall2)
SetObject3DPhysicsGroupAndMask(wall2,1,2)
wall3=CreateObjectBox(5,150,800)
SetObjectposition(wall3,400,0,0)
setobjectcolor(wall3,random(50,200),random(50,200),random(50,200),255)
Create3DPhysicsStaticBody(wall3)
SetObject3DPhysicsGroupAndMask(wall3,1,2)
wall4=CreateObjectBox(5,150,800)
SetObjectposition(wall4,-400,0,0)
setobjectcolor(wall4,random(50,200),random(50,200),random(50,200),255)
Create3DPhysicsStaticBody(wall4)
SetObject3DPhysicsGroupAndMask(wall4,1,2)
// xxxxxxxxxxxxxxxxxxxxxx boxes don't collide with boxes
maxBoxes=100
for i=1 to maxBoxes
boxID=i+1000
boxXpos=random(0,500)-250
boxZpos=random(0,500)-250
CreateObjectBox(boxID,7,7,7)
SetObjectposition(boxID,boxXpos,100,boxZpos)
SetObjectrotation(boxID,boxXpos,100,boxZpos)
setobjectcolor(boxID,random(50,200),random(50,200),random(50,200),255)
Create3DPhysicsDynamicBody(boxID)
SetObject3DPhysicsCanSleep(boxID,0)
SetObject3DPhysicsRestitution(boxID,1)
SetObject3DPhysicsFriction(boxID,3.0)
SetObject3DPhysicsMass(boxID,0.5)
SetObject3DPhysicsGroupAndMask(boxID,2,1)
next i
// xxxxxxxxxxxxxxxxxxxx camera setup
cam1=1
SetCameraRange(cam1, 0.1, 50000 )
SetCameraposition(cam1,410,200,410)
SetCameraRotation(cam1,20,225,0)
man1=CreateObjectsphere(2,6,12)
SetObjectposition(man1,410,200,410)
setobjectvisible(man1,0)
SetObjectRotation(man1,0,225,0)
// xxxxxxxxxxxxxxxxxxxx stuff
sights=CreateSprite(0)
SetSpriteSize(sights,height#/400,height#/400)
SetSpritePosition(sights,width#/2-getspritewidth(sights)/2,height#/2-getspriteheight(sights)/2)
target=createobjectbox(1,1,1) // gives end coords for ray
setobjectvisible(target,0)
bomb=createobjectsphere(5,6,12)
SetObjectColor(bomb,255,255,50,255)
bombpos#=CreateVector3(0,0,0)
boxpos#=CreateVector3(0,0,0)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
attract=0
setrawmousevisible(0)
SetRawMousePosition(width#/2,height#/2)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx playerShip
playerShip=createobjectbox(50,20,100)
SetObjectposition(playerShip,0,200,0)
SetObjectrotation(playerShip,0,100,0)
setobjectcolor(playerShip,random(50,200),random(50,200),random(50,200),255)
Create3DPhysicsDynamicBody(playerShip)
//SetObject3DPhysicsCanSleep(playerShip,0)
//SetObject3DPhysicsRestitution(playerShip,1)
//SetObject3DPhysicsFriction(playerShip,3.0)
SetObject3DPhysicsMass(playerShip,0.5)
SetObject3DPhysicsGroupAndMask(playerShip,2,1)
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX main loop
do
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxx camera control
mouseX# = (GetRawMouseX()-width#/2)*0.1
mouseY# = (GetRawMouseY()-height#/2)*0.1
RotateCameraLocalX(cam1,mouseY#)
RotateObjectLocalY(man1,mouseX#)
SetCameraRotation(cam1,GetCameraAngleX(cam1),GetObjectAngleY(man1),0)
If GetCameraAngleX(cam1)>80 Then SetCameraRotation(cam1,80,GetCameraAngleY(cam1),0)
If GetCameraAngleX(cam1)<-80 Then SetCameraRotation(cam1,-80,GetCameraAngleY(cam1),0)
if GetRawKeyState(87) then MoveObjectLocalZ(man1,2) // W forward
if GetRawKeyState(83) then MoveObjectLocalZ(man1,-2) // S backward
if GetRawKeyState(65) then MoveObjectLocalX(man1,-2) // A strafe left
if GetRawKeyState(68) then MoveObjectLocalX(man1,2) // D strafe right
if GetRawKeyState(81) then MoveObjectLocalY(man1,-1) // Q down
if GetRawKeyState(69) then MoveObjectLocalY(man1,1) // E up
SetCameraPosition(cam1,GetObjectX(man1),GetObjectY(man1),GetObjectZ(man1))
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx LMB to place marker
if GetRawMouseLeftPressed()
// "target" is an invisible box used for end of ray coords
setobjectposition(target,GetCameraWorldX(cam1),GetCameraWorldY(cam1),GetCameraWorldZ(cam1))
setobjectrotation(target,GetCameraAngleX(cam1),GetCameraAngleY(cam1),GetCameraAngleZ(cam1))
moveobjectlocalZ(target,5000)
ray1=ObjectRayCast(0,GetCameraWorldX(cam1),GetCameraWorldY(cam1),GetCameraWorldZ(cam1),GetObjectWorldX(target),GetObjectWorldY(target),GetObjectWorldZ(target))
setobjectposition(bomb,GetObjectRayCastX(0),GetObjectRayCastY(0),GetObjectRayCastZ(0))
endif
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx RMB to apply force
if GetRawMouseRightState()
SetVector3(bombpos#,getobjectX(bomb),getobjectY(bomb),getobjectZ(bomb))
for s=1 to maxBoxes
SetVector3(boxpos#,getobjectX(s+1000),getobjectY(s+1000),getobjectZ(s+1000))
force#= -GetVector3Distance(bombpos#,boxpos#) + 430 // sets force range and strength
if force#>0
if attract=0
SetObject3DPhysicsLinearVelocity(s+1000,(GetObjectX(s+1000)-GetObjectX(bomb)),(GetObjectY(s+1000)-GetObjectY(bomb)),(GetObjectZ(s+1000)-GetObjectZ(bomb)),force#)
else
SetObject3DPhysicsLinearVelocity(s+1000,-(GetObjectX(s+1000)-GetObjectX(bomb)),-(GetObjectY(s+1000)-GetObjectY(bomb)),-(GetObjectZ(s+1000)-GetObjectZ(bomb)),force#)
endif
endif
next s
endif
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx MMB to switch between attract and repel
if GetRawMouseMiddlePressed()
attract=1-attract
endif
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx angle stuff
if GetRawKeyState(37) // key left arrow
SetObject3DPhysicsAngularVelocity(playerShip,0,-GetObjectAngleY(playerShip),0,50)
endif
if GetRawKeyState(39) // key right arrow
SetObject3DPhysicsAngularVelocity(playerShip,0,GetObjectAngleY(playerShip),0,50)
endif
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
print(" LMB place marker")
print(" RMB apply force")
print(" MMB to switch")
if attract=0
print(" repel")
else
print(" attract")
endif
print(" L R arrow keys rotate dummy ship block thingy")
Step3DPhysicsWorld()
SetRawMousePosition(width#/2,height#/2)
Sync()
if GetrawKeyPressed(27) then end
loop
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.