I have got oildrums,barrels etc in my game all of which have a convex hull type body.When the player collides with them they go haywire and fly around. This did not happen at first but has occured as I put more stuff in my code.In the log "failed to load sound" is the only warning or error.Seems to work ok in the editor.
SuperStrict
Framework leadwerks.framewerk
GCSetMode(2)
RegisterAbstractPath AppDir
Graphics(800, 600,32)
Global fw:TFramewerk = TFramewerk.Create()
If Not fw RuntimeError "Failed to initialize engine."
'Set global objects for lua scripted entities
SetGlobals()
'Set collisions
SetCollisions()
'Load scene
Local scene:TEntity = LoadScene("abstract::game02.sbx")
Local entity:TEntity
AmbientLight([0.3, 0.3, 0.3])
'debugphysics(1)
'create controller
Local player:TController = CreateController(1.8,0.5)
Local playermesh:TMesh =CreateCylinder(32)
ScaleMesh(playerMesh,Vec3(0.8,1.2,0.8))
HideEntity playermesh
EntityType player, 2
PositionEntity(player, StringToVec3(scene.getkey("cameraposition")))
SetBodyMass(player, 4.0)
'movement variables
Local move:Float = 0.0
Local strafe:Float = 0.0
Local camrotation:TVec3 = Vec3(0)
Local mx:Float = 0.0
Local my:Float = 0.0
Local jump:Float = 0.0
HideMouse()
'================================================
Local door_1:TEntity
Local key:TEntity
Local gotkey:Int = False
For Local e:TEntity = EachIn CurrentWorld().Entities
Select GetEntityKey(e, "Name")
Case "key"
key = TEntity(e)
Case "door_1"
door_1 = TEntity(e)
EndSelect
Next
'===================================================
Repeat
If KeyHit(KEY_ESCAPE) Exit
If AppTerminate() Exit
'camera movement
mx = Curve(MouseX() - GraphicsWidth() / 2, mx, 6)
my = Curve(MouseY() - GraphicsHeight() / 2, my, 6)
MoveMouse(GraphicsWidth() / 2, GraphicsHeight() / 2)
camrotation.X = camrotation.X + my / 10.0
camrotation.Y = camrotation.Y - mx / 10.0
RotateEntity(fw.Main.camera, camrotation)
'controller movement
move = KeyDown(KEY_W) - KeyDown(KEY_S)
strafe = KeyDown(KEY_D) - KeyDown(KEY_A)
jump:Float = 0.0
If KeyHit(KEY_SPACE) & Not ControllerAirborne(player)
jump = 4.0
End If
If KeyDown(KEY_LSHIFT) | KeyDown(KEY_RSHIFT)
move = move * 3.0
strafe = strafe * 3.0
End If
Local playerpos:TVec3 = EntityPosition(player)
playerpos.Y = playerpos.Y + 0.90
PositionEntity(fw.Main.camera, playerpos)
UpdateController(player, camrotation.Y, move * 6, strafe * 6, jump, 1500, 1)
If EntityDistance(player,key) < 2 And KeyHit(KEY_G)
HideEntity key
gotkey = True
EndIf
If gotkey = True
If EntityDistance(player,door_1) < 3
MoveEntity door_1,vec3(0.1,0,0)
EndIf
EndIf
PositionEntity playermesh,entityposition(player)
fw.Update()
fw.Render()
Flip(1)
Forever
fw.renderer.gbuffer = Null
GCCollect()
End
Function SetGlobals()
'SetGlobalObject("listener", CreateListener(fw.Main.camera))
SetGlobalObject("world_main", fw.Main.world)
SetGlobalObject("world_transparency", fw.transparency.world)
SetGlobalObject("world_background", fw.background.world)
SetGlobalObject("camera_main", fw.Main.camera)
SetGlobalObject("camera_transparency", fw.transparency.camera)
SetGlobalObject("camera_background", fw.background.camera)
SetGlobalObject("renderer_world", fw.renderer)
SetGlobalObject("fw", fw)
SetGlobalObject("listener", CreateListener(fw.Main.camera))
End Function
Function SetCollisions()
Collisions(1, 1, 1)
Collisions(1, 2, 1)
Collisions(1, 3, 1)
Collisions(2, 2, 1)
Collisions(2, 3, 1)
Collisions(3, 3, 1)
End Function
Function StringToVec3:TVec3(text:String, scale:Float = 1.0)
Local t:TVec3 = Vec3(1)
Local sarr:String[]
sarr = text.split(",")
If sarr
If sarr.length > 0 t.x = Float(sarr[0]) * scale
If sarr.length > 1 t.y = Float(sarr[1]) * scale
If sarr.length > 2 t.z = Float(sarr[2]) * scale
EndIf
Return t
EndFunction