Jump to content

self.entity:Hide() problem.


Braqoon
 Share

Recommended Posts

Hi, I'm not sure do I miss something obvious but for me self.entity:Hide() does not work as intended.

 

Below I got a very simple enemy LUA script, which should on collision be 'removed' from gameplay.

Object on collision does get hidden and not being rendered but it's still there and all the physics apply.

 

According to http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entityhide-r181 this should not be the case.

 

function Script:Start()
self.entity:SetMass(1)
self.entity:SetGravityMode(false)
self.entity:SetFriction(0,0)
self.entity:SetCollisionType(Collision.Prop)
self.health=50
self.points= 100
self.endof = 0
end
function Script:Collision(entity)
self:Hurt(100)
end
function Script:Hurt(damage)
if self.health > 0 then
self.health = self.health - damage
if self.health<= 0 then
self.entity:Hide()
self.entity:SetMass(0)
self.entity:SetCollisionType(0)
PlayerScore=PlayerScore+self.points

end
end
end

function Script:UpdatePhysics()
--Get the game window
local window = Window:GetCurrent()
local evel = Vec3(0,0,-5)
self.entity:SetVelocity(evel)
end

 

Can somebody explain ? Just to be clear Hurt is triggered on it's own when bullet hits the enemy with this script attached to it where collision is with player's model (currently a box). Regardless of collision with the player or hit by the bullet, self.entity:Hide() just stops rendering the object on the screen but it's still there and after respawn (respawn not reload) I can hit it again when enemy is hidden.

Link to comment
Share on other sites

I am not having any collision with a hidden object, but i wonder if something is being messed up in your script based on the number of collisions being reported on first contact much like in your previous post. Suggest putting in a logic check to only allow the first reported collision to call the 'Hurt' function:

 

function Script:Start()

...

self.toggle = 1

end

 

function Script:Collision(entity)

if self.toggle==1 then

self.toggle = 0

self:Hurt(100)

end

end

  • Upvote 1

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

Yes, thought about it but this made no difference. Hide for me only hides object from rendering. Other test is that I can trigger a collision with bullet so my player does not touch it. Enemy is hidden but then it stays on the scene and player can hit it. Anyway Release works as it should so not a big problem for now.

  • Upvote 2
Link to comment
Share on other sites

If you found a work around then good. If you ever see this issue again, I would suggest posting an actual example showing hidden objects still colliding because I cannot make it happen and would be curious to see an example of the problem.

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

Videos and pics are nice but for something like this I would like to see a working example if possible so that i could test myself. Like I alluded to above, I was not getting collision with a hidden object - using the object script you posted attached to a csg box. So I would be curious to see something I could test that causes this problem.

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

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