Jump to content

[LUA] Collision:SetResponse() causes error


Recommended Posts

The request had been to implement user defined collision types and responses as shown in this post: http://www.leadwerks.com/werkspace/topic/9109-collision-response-types/#entry73689

 

And the documentation page says that the programmer can change the default collision responses, but whenever 'Collision:SetResponse()' is used it will error out with 'argument #1 is class Collision; Collision expected'.

 

Example code - uncomment the line to cause the error:

function App:Start()
 --Create a window
 self.window = Window:Create()
 self.context = Context:Create(self.window)
 self.world = World:Create()
 local camera = Camera:Create()
 camera:SetRotation(35,0,0)
 camera:Move(0,0,-8)
 local light = DirectionalLight:Create()
 light:SetRotation(35,35,0)

 --Create the ground
 local ground = Model:Box(10,1,10)
 ground:SetColor(0.0,1.0,0.0)

 --Create a shape
 local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10)
 ground:SetShape(shape)
 shape:Release()

 --Create a model
 self.entity1 = Model:Box()
 self.entity1:SetColor(0.0,0.0,1.0)
 self.entity1:SetPosition(-2,3,0)
 self.entity1:SetMass(1)
 self.entity1:SetCollisionType(2)

 --Create a shape
 shape = Shape:Box()
 self.entity1:SetShape(shape)
 shape:Release()

 --Create a second model
 self.entity2 = self.entity1:Instance()
 self.entity2:SetPosition(2,3,0)
 self.entity2:SetCollisionType(13)
--Collision:SetResponse(1,13,true)---UNCOMMENT THIS LINE TO CAUSE ERROR
 return true
end
function App:Loop()

 if self.window:Closed() or self.window:KeyHit(Key.Escape) then return false end
 Time:Update()
 self.world:Update()
 self.world:Render()
 self.context:SetBlendMode(Blend.Alpha)
 self.context:DrawText("Entity 1 collision type: "..self.entity1:GetCollisionType(),2,2)
 self.context:DrawText("Entity 2 collision type: "..self.entity2:GetCollisionType(),2,22)
 self.context:Sync()
 return true
end

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

  • 2 weeks later...

Thank you. The function was not declared as a static function, which it should have been.

 

BTW, the third argument is a number, not a boolean:

0: no response

1: collide

2: trigger

  • Upvote 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...