YouGroove Posted February 8, 2014 Share Posted February 8, 2014 I go that standard code in Lua : function Script:Collision(entity, position, normal, speed) How to detect the name of Enity ? Function getName() seems not to exist ? To detect if entity incollision name ="player for example. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted February 8, 2014 Share Posted February 8, 2014 entitty:GeyKeyValue("name", "") 2nd param is the value if no key exists Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 8, 2014 Author Share Posted February 8, 2014 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 ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted February 8, 2014 Share Posted February 8, 2014 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 Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 9, 2014 Author Share Posted February 9, 2014 That's weird. Tried but didn't worked : local type = entity:GetKeyValue("type", "") if type == "player" then self.entity:Stop() end Well perhaps try to retrieve script not nil and script name = "player" for example ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted February 9, 2014 Author Share Posted February 9, 2014 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") Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted February 9, 2014 Author Share Posted February 9, 2014 AHAHAHA 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 I'm digging the great Lua code that is short and simple to understand, Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Recommended Posts
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.