Jump to content

Lua Collision : Get entity name


YouGroove
 Share

Recommended Posts

Hummm .. strange seems not working perhaps because alien collides with floor first ?

Perhaps it returns the colliding floor always and overwrite Player collision ?

 

I got that for Player code in start() :

self.entity:SetKeyValue("name","Player")

 

And for Alien :

function Script:Collision(entity, position, normal, speed)

  if entity:GetKeyValue("name") == "Player" then
   self.entity:Stop()
  end
end

 

This is Collision that must not work as i expect, perhaps it returns nil or "floor" each time ?

Stop toying and make games

Link to comment
Share on other sites

Not that this is the issue, but you don't have to set the name key in your script. The name key automatically gets the name from the editor, but it doesn't hurt and shouldn't cause this issue, just something to point out.

 

I'm using this technique for your bomb models when they collide with the player so it does work. What you have looks right so the problem must be somewhere else. I just made a "type" key instead but below is what I have attached to the bomb models which are character controllers for physics:

 

function Script:Collision(entity, position, normal, speed)
   if self.Alive == false then return end

   local type = entity:GetKeyValue("type", "")

   if type == "player" then
       self:Explode(true)

       entity.script:Hurt()
   end
end

Link to comment
Share on other sites

Here is my script , something must be wrong ?

 

Alien :

 


function Script:Start()
   self.entity:SetFriction(0,0)
   self.entity:SetKeyValue("name","alien")
end



function Script:Collision(entity, position, normal, speed)


   local type = entity:GetKeyValue("type", "")

   if type == "player" then
       self.entity:Stop()
       self.entity:SetPosition(0,0,0)

   end

end

 

Player :

 

 

 

Start :

 


   self.entity:SetKeyValue("name","Player")

Stop toying and make games

Link to comment
Share on other sites

AHAHAHA laugh.png

 

Stupid me :

self.entity:SetKeyValue("name","alien")

 

 

must be instead :

 

self.entity:SetKeyValue("type","alien")

 

And it worked just fine.

 

------------

 

Big thanks for your help Rick and your fun Bomb game smile.png

I'm digging the great Lua code that is short and simple to understand,

Stop toying and make games

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