Jump to content
Braqoon

self.entity:Hide() problem.

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.

Share this post


Link to post

Open up the EnemyAi.lua script that is included in the advanced fps player project type. Theres also a function like that but without the Hide().

Share this post


Link to post

self.entity:Release() does the trick but docs should be updated on self.entity:Hide() if it does not do what it says.

 

Thanks.

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

sure, Can provide project. Will create from scratch with same scripts so will do test myself as well. Bare with me.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...