Jump to content

Recommended Posts

Posted

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.

Stop toying and make games

Posted

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

Posted

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

Posted

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 ?

Stop toying and make games

Posted

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

Posted

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

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.

×
×
  • Create New...