Jump to content

Entity specific collisions


NotSoSavvy
 Share

Recommended Posts

Morning all. I'll preface this with the always-worrying "I'm new to this but I'm learning" statement so you know what you're getting into.

 

Now, my problem is that I'm trying to write a lua collision script that only recognises a specific non-player object. I've got a part in the middle that we will call Lathe, and a hitbox around it. If I place a specific other part within that hitbox, let's call it Drill, I want the collision script to activate. I don't want it to activate for any other collision.

 

So...possible? I haven't had a vast amount of luck trying to modify the standard collision script, and can't find any obvious documentation on it.

Link to comment
Share on other sites

Thank you, that solved it! One problem down, several thousand unknown ones to go. Marvelous.

 

Edit: Well, it solved it as long as the selected entity is me. No luck with a selected box falling into it. Does the collision box default to only reacting to certain types of entity?

Link to comment
Share on other sites

What I do is define variables in each of my classes. I just call it something like:

 

Script.entityType = "Player"

 

Then on the other entity that I want to get a collision with, I just check what object type I'm colliding with:

 

if entity.script.entityType == "Player" then
 -- Do something
end

Link to comment
Share on other sites

@Marcus

 

If something that doesn't have that variable hits the script I think the script would give an error. Doing a check that the variable exists should help avoid that.

 

if entity.script.entityType ~= nil then
  if entity.script.entityType == "Player" then
  end
end

Link to comment
Share on other sites

@Marcus

 

If something that doesn't have that variable hits the script I think the script would give an error. Doing a check that the variable exists should help avoid that.

 

if entity.script.entityType ~= nil then
if entity.script.entityType == "Player" then
end
end

 

Good catch.

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