Jump to content

collisions problem


cassius
 Share

Recommended Posts

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

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

why do your oildrums have a convex hull body? I am pretty sure the prop's PHY that comes with LE is a cylinder...

 

also whats the point of the playermesh? and the constant positioning of it to the player? Assuming that it actually serves a purpose, just parent it to the player and be done with it...

 

whats the mass of your barrels? have you tried changing your acceleration? also that controller code doesn't have the character collision set correctly... it should be 3...

 

have you tried this with the version i posted in my blog?

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

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

I got rid of the cube (playermesh and changed entitytype player to 3. thanks again. It worked.

 

well, I am the one that had the code wrong to begin with... but right now i am not too sure why i thought collision response of 3 is swept collision? i can't find it any where in the wiki but for some reason i just thought it was...

 

yeah i guess i need to change that code in my blog as well... i didn't really test it as far as running into props... was just using to run around a scene and look at stuff for the most part atm...

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 use convex hull mainly cos its such a pain doing anything else. Takes me ages to do spheres and cylinders.

 

no i do that too... just was throwing things out there because i know the oildrum phy is not a convex hull... but i guess it was the wrong collision setting... but i be damned if i can find a response of 3 in the wiki...

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 am still having the same collisions problem even with macklebee's corrected code but since around 50 other people have downloaded it and noone else has reported a similar problem I can only assume I am getting something wrong elsewhere, possibly in the editor, but I can't see what.

the game runs fine in the editor. I am using the version of phygen that came with 2.3 and all my models have new phy files.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

I have tried Macks code, the controller set to a body mass of 10, without the adjustment to the collisons that is:

 

Collisions(1, 3, 1)

 

The barrels will fly all over the place when bumped into .. but using the suggested adjustment:

 

Collisions(1, 3, 3)

 

They act normally for me.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

cassius, if you are comparing how my code reacts versus the fpscontroller ran in the editor, then you need to set everything exactly the same... the controller weight is different, the updatecontroller's (controller:Update() in lua) acceleration and iteration values are different... all of these things come into play.

 

anyone else find any reference to what 3 is in the collisions command?

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 just found that adding a little body force to the player fixes the problem I had when the player seemed to go thru the oildrums. Now it makes them look solid and works just like in the editor.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

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