Jump to content

cassius

Members
  • Posts

    2,834
  • Joined

  • Last visited

Posts posted by cassius

  1. I added the cube ( playermesh)because I was having the problem before. One of the oildrums came with the sdk I dont know the type of phy file it has but it flies around just the same. but thanks i will go back to your original code.

  2. 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

  3. Thanks maclebee. I am using the listing you gave the community. I have added a cube (invisible) and parented to the controller. It works fine for collisions but need a bit more impetus going up stairs. I will check acceleration.

  4. am not getting oildrum sound in my app. Its ok in editor. Script folder is in my projects folder.

    I got this code in app

    SetGlobalObject("listener", CreateListener(fw.Main.camera))

    Any ideas? Thanks.

  5. Yes I mean the name of the entity in the property dialog.

    At the moment when I run my game in bmax I just get a black screen. I assume I am not landing inside the level which is an interior level.If thats not the case then something else is wrong.

     

    EDIT:Ah! its working now.I just took camera position numbers from sbx file and started game tat that point.Thanks.

  6. I too would like to repay the community for fantastic help over a long period but mostly my lack of expertise prevents it. I do however recommend le and the community at every oportunity.

    It might be nice to have a "How to" section on the forum like:

    How to open and close doors in a game

    How to make an elevator go up and down

    How to pick up objects....etc

  7. Thanks macklebee.

    I got rid of the code last nijht after a couple of frustrating hours. The program ran with no errors. The lighting was on and you could lookaround with mouse but movement was frozen.

     

    The problem was I did'nt know which commands were obsolete or no longer needed.

    Is it true that LoadScene takes care of lighting now?

  8. I have been trying to update the character controller code on the wiki for use with le 2.3 but had no success.

    I need some code that will put a player inside a level with look around and mocement capability.

    If anyone would share such code it would be much apreciated.

×
×
  • Create New...