Cole Chapman Posted August 2, 2011 Share Posted August 2, 2011 I used Marleys Third Person Cam tutorial and made a Player Type but I cannot get collisions to work. The only differences as far as I can tell is I did not use (and do not want to) use LUA functions and I use MaxGUI(though I cannot see how that would make a difference) The Code: SuperStrict Framework Leadwerks.Engine Import "Framework.BMX" Import MaxGUI.MaxGUI Import MaxGUI.Drivers Import BRL.EventQueue RegisterAbstractPath("C:\Leadwerks Engine SDK") GCSetMode(2) Global FW:TFramework Local GEWindow:TGadget Local GEWindowX:Int 'Null (WINDOW_CENTER) Local GEWindowY:Int 'Null (WINDOW_CENTER) Local GEWindowW:Int = 800 Local GEWindowH:Int = 600 Local GEWindowStyle:Int = WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_MENU|WINDOW_STATUS|WINDOW_CENTER Local Canvas1:TGadget Global Terrain:TTerrain Global TerrainText:TTexture Global Light:TLight DebugPhysics(1) Type TPlayer Global Current:TPlayer Field Controller:TController Field Move:Float Field Strafe:Float Field CamRotation:TVec3 Field MX:Float Field MY:Float Field Jump:Float Field Position:TVec3 Field Body:TEntity Field CamY:Float Field CamZ:Float Function Create:TPlayer() Local Player:TPlayer = New TPlayer Player.Move:Float = 0.0 Player.Strafe:Float = 0.0 Player.CamRotation:TVec3 = Vec3(0) Player.MX:Float = 0.0 Player.MY:Float = 0.0 Player.Jump:Float = 0.0 Player.CamY:Float = 0.0 Player.CamZ:Float = 0.0 Player.Controller = CreateController(2.0) PositionEntity(Player.Controller, EntityPosition(FW.Main.Camera)) EntityType(Player.Controller, 3) SetBodyMass(Player.Controller, 10.0) SetBodyBuoyancyMode(Player.Controller, 0) Collisions(1, 3, 3) Player.Body:TEntity = CreateCube(Player.Controller) ScaleEntity(Player.Body, Vec3(0.5, 1.8, 0.5)) Return Player EndFunction Method Update() Self.MX = Curve(MouseX() - GraphicsWidth() / 2, Self.MX, 6) Self.MY = Curve(MouseY() - GraphicsHeight() / 2, Self.MY, 6) MoveMouse(GraphicsWidth()/2, GraphicsHeight()/2) Self.CamRotation.X = Self.CamRotation.X + Self.MX / 10.0 Self.CamRotation.Y = Self.CamRotation.Y - Self.MX / 10.0 RotateEntity(FW.Main.Camera, Self.CamRotation) If Self.CamRotation.X > 90.0 Then Self.CamRotation.X = 90.0 If Self.CamRotation.X < -20.0 Then Self.CamRotation.X = -20.0 Self.Move = KeyDown(KEY_W) - KeyDown(KEY_S) Self.Strafe = KeyDown(KEY_D) - KeyDown(KEY_A) Self.Jump:Float = 0.0 If KeyHit(KEY_SPACE) And Not ControllerAirborne(Self.Controller) Then Self.Jump = 4.0 EndIf If KeyDown(KEY_LSHIFT) Or KeyDown(KEY_RSHIFT) Then Self.Move = Self.Move * 3.0 Self.Strafe = Self.Strafe * 3.0 EndIf PositionEntity(FW.Main.Camera, Vec3(Self.Controller.Position.X, Self.Controller.Position.Y + 0.8, Self.Controller.Position.Z)) Self.CamY = 0.5 If MouseZ() > 0 Then FlushMouse() If MouseZ() < 0 Then Self.CamY = 0.0 Self.CamZ = Curve(MouseZ(), Self.CamZ, 10) MoveEntity(FW.Main.Camera, Vec3(0, Self.CamY, Self.CamZ)) UpdateController(Self.Controller, Self.CamRotation.Y, Self.Move * 3, Self.Strafe * 3, Self.Jump, 0.5) EndMethod EndType GEWindow:TGadget = CreateWindow("GE", GEWindowX, GEWindowY, GEWindowW, GEWindowH, Null, GEWindowStyle) Canvas1:TGadget = CreateCanvas(0, 0, ClientWidth(GEWindow), ClientHeight(GEWindow), GEWindow) SetGadgetLayout(Canvas1, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED) SetGraphics(CanvasGraphics(Canvas1)) ActivateGadget(Canvas1) EnablePolledInput() FW:TFramework = CreateFramework() If Not FW RuntimeError "Failed to Initialize Engine" Terrain = CreateTerrain(2048) LoadTerrainHeightmap(Terrain, "Terrain.raw") TerrainText = LoadTexture("TerrainGrass.dds") SetTerrainTexture(Terrain, TerrainText, 0, 0) PositionEntity(FW.Main.Camera, Vec3(0.0, 1000.0, 0.0)) Light:TLight = CreateDirectionalLight() PositionEntity(Light, Vec3(0.0, 350.0, 0.0)) RotateEntity(Light, Vec3(45,45,0)) CameraRange(FW.Main.Camera, 0.1, 750.0) SetSkyBox(LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat")) SetBackGroundColor(Vec4(1,1,1,1)) SetFarDOF(1) SetFarDOFStrength(1) SetFarDOFRange(600.0, 750.0) Global MainPlayer:TPlayer MainPlayer:TPlayer = TPlayer.Create() If Not MainPlayer RuntimeError "Failed to Create Player." Repeat While PeekEvent() WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_WINDOWSIZE SetGraphics CanvasGraphics(Canvas1) EndSelect Wend MainPlayer.Update() If KeyDown(KEY_ESCAPE) Then End FW.Update() FW.Render() SetBlend(1) DrawText(MouseX(), 0, 10) SetBlend(0) Flip(0) Forever GCCollect() End Quote Link to comment Share on other sites More sharing options...
Richard Simpson Posted August 2, 2011 Share Posted August 2, 2011 This is a total stab in the dark, as I am only learning to code, but have you tried to compile without "SuperStrict" ? Quote Intel core 2 quad 6600 | Nvidia Geforce GTX460 1GB | 2GB DDR2 Ram | Windows 7. Google Sketchup | Photoshop | Blender | UU3D | Leadwerks Engine 2.4 Link to comment Share on other sites More sharing options...
Cole Chapman Posted August 2, 2011 Author Share Posted August 2, 2011 Just tried it, no luck =/ Quote Link to comment Share on other sites More sharing options...
Richard Simpson Posted August 2, 2011 Share Posted August 2, 2011 Would this work? I noticed you don't have "True" in your collisions line. Collisions(1, 3, 3,True) Quote Intel core 2 quad 6600 | Nvidia Geforce GTX460 1GB | 2GB DDR2 Ram | Windows 7. Google Sketchup | Photoshop | Blender | UU3D | Leadwerks Engine 2.4 Link to comment Share on other sites More sharing options...
macklebee Posted August 2, 2011 Share Posted August 2, 2011 close Richard... that line is the problem though... he is setting the collision response to something that doesn't exist. CollisionsBlitzMax: Collisions( collisionType1, collisionType2, collisionResponse ) Sets the collision response for collision type 1 and 2. 0 - no collision (default) 1 - sliding collision 2 - no-response collision; a collision is recorded, but the objects will pass through each other. so the line should read: Collisions(1, 3, 1) Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Cole Chapman Posted August 2, 2011 Author Share Posted August 2, 2011 Collisions only have three parameters, The first two are (I BELIEVE) Entity Groups in a way and the third is what happens if Entities from those groups collide. I have tried Collisions(1, 3, True) Collisions(1, 3, 1) Collisions(1, 3, 2) Collisions(1, 3, 3) And I have also assigned EntityType(Terrain, 1,2,3,etc with no such luck. Marleys code works though and I am hoping its not because of the LUA stuff Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 2, 2011 Share Posted August 2, 2011 well first thing is that you are turning the controller into a bullet by setting its position 1000 meters above the terrain... so by the time it hits the terrain its going so fast it passes through the terrain. Try setting the camera only 1 or 2 meters in the Y axis or try setting swept collision for the controller. Also along with the setting the collisiontype for the controller you must also set the collision type for the terrain. Then you have to set the collision response for each possible collisiontype. Also I am not sure what your hesitation is with using the lua scripts, but they work great for setting up the normal parameters like collisiontypes/responses. In any case, you should probably try just loading a SBX with LoadScene instead of trying to create a terrain. You have multiple issues here - collisions, camera rotation/placement, DOF set so everything is a blur, etc... that just compound your problems when trying to troubleshoot. If you attempt one thing at a time and rely on proven methods first, then it makes troubleshooting your code alot easier on yourself... just a helpful suggestion... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Cole Chapman Posted August 2, 2011 Author Share Posted August 2, 2011 Ah, the bullet thing is what did it. Ill look into Swept Collision. Thanks man! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.