Jump to content

Help with physics please?


Richard Simpson
 Share

Recommended Posts

I'm playing around with blitzmax again and doing the tutorials. I'm stuck with collisions now though as I am trying to use my own mesh with a PHY file. I want a box created with code to collide with my sbx scene I have loaded. Here is the code: (I have left in the lines where I have tried to use my level variable to create collision)

 

'Load the leadwerks game engine framework
Framework leadwerks.engine

'Specify the app title
AppTitle$ = "Test App"

'Create a graphics window
Graphics 1280,900

'Register the abstract path
registerabstractpath AppDir

'Create world with error message if world fails to load
If Not CreateWorld() RuntimeError "Failed to load the world."

'Create a camera and position it
camera:Tcamera = CreateCamera()
PositionEntity camera,vec3(0,2,-6)
RotateEntity camera,vec3(0,-30,0)

'Create a light, position and rotate it
sun:TLight = CreateDirectionalLight()
PositionEntity sun,vec3(2,2,-2)
RotateEntity sun,vec3(45,45,0)

'Create the player
player:TMesh = CreateCube()
EntityParent camera,player

'Load level 1
level1 = LoadScene("abstract::level1.sbx")
positionentity level1,vec3(0,-2,0)

'--------Create physics bodies--------
playerbody:TBody = createbodybox()
setbodymass playerbody,1
EntityParent player,playerbody


entitytype playerbody,1
entitytype level1,1
collisions 1,1,True



'Create a buffer
buffer:TBuffer = CreateBuffer(1280,900,BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL)

'Debug lights and physics
debuglights(0)
debugphysics(1)

'Main loop
While Not KeyHit(KEY_ESCAPE)

'Move the player left and right
If KeyDown(KEY_A) moveentity player,vec3(-0.06,0,0)
If KeyDown(KEY_D) moveentity player,vec3(0.06,0,0)

'Zoom camera in and out, reset camera position
If KeyHit(KEY_NUM1) moveentity camera,vec3(0,0,1)
If KeyHit(KEY_NUM2) moveentity camera,vec3(0,0,-1)
If KeyHit(KEY_NUM0) positionentity camera,vec3(0,0,-6)


'Update, render and flip the world
updateworld()
setbuffer buffer

renderworld()
setbuffer backbuffer()

renderlights(buffer)
Flip

Wend

 

Thanks! :)

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

You cannot set the position of the scene. Also since the playerbody is being created at 0,0,0 and that is the center of the bodybox, the bottom half of the playerbody is already passed through the terrain when the app starts. Set the playerbody so that the entire object is above the terrain (assuming you have a terrain... if not then it needs to be placed completely above the mesh you wish it to sit upon when the app starts)

positionentity(playerbody,vec3(0,2,0))

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

I did try this, but it's still not colliding :) I removed the "positionentity level1,vec3(0,-2,0)" and then added in the line you posted. I added that line in here...

 

 

'--------Create physics bodies--------
playerbody:TBody = createbodybox()
positionentity(playerbody,vec3(0,5,0))
setbodymass playerbody,1
EntityParent player,playerbody


entitytype playerbody,1
entitytype level1,1
collisions 1,1,True

 

The created body does drop down, but it just wont collide with the level.

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

The third parameter to Collisions() is not a boolean, but a integer.

 

You need to set the entitytypes of the level objects also, the best with their properties dialog in Editor, and you need to set the entitytype for the terrain too.

You could simple do a EntityType(level,1,1) to recursively set all level entities to 1, if you don't need any more detailed collisions.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...