Jump to content

Collision with particular object?


Andy Gilbert
 Share

Recommended Posts

Hi, ive done a search but cant seem to find the answer.

 

What is the current way using lua to detect a collsion with a particular object?

 

Can i determind the collsion using the objects name somwhow?

 

Thanks

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

You can use the objects name with something like: entity:GetKeyValue("name"). I would however say this isn't the best way as it's sort of bastardizing the name field and isn't as flexible as making another key specifically for "type" or something like that. This would be much easier and better with multiple scripts per entity ( ;) ) but you can do it with the same script. Just expose a type string variable to objects and then check the type and determine what to do from there. entity:GetKeyValue("type").

 

One thing I did with this is to identify the "floor" vs walls an everything else for the pathfinding. If I have a game where the player moves where I click, then if I click on a wall the player would try to move there. To prevent this when there were multiple scripts per entity I made a Lua script specifically just to expose a Type string variable and set it's value to "floor" and check that when I do the picking and only try to move if it's of type "floor". You can do the same with 1 script but you have to put this code into each script, duplicating the effort.

Link to comment
Share on other sites

Can't you just check for the normal in the collision to check if it is a wall or the floor?

 

that way you would not need to add a script to the CSG objects which would disable the internal optimization for it.

 

Another way could be to check the collisiontype.

Link to comment
Share on other sites

I'd have to test the normal collision to see if that works. I felt the script way was the most flexible but of course requires more work to be done.

 

 

You'd still have to define the collision type as I don't think there is a default wall/floor in LE. So you'd need a way to define that and that would be in a script right? Then you are back to doing it in a script anyway.

Link to comment
Share on other sites

Sorry to be a pain, but is there some example script of how this is actually achived or what functions to use?

 

Its a simple test, between one object and another.

 

Thanks

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

If you have a moving object and a stationary object.

Call your moving object gobbo in the Scene editor.

attach the following script to the stationary object.

function Script:Collision(entity, position, normal, speed)
being = entity:GetKeyValue("name")
if being == "gobbo" then self.entity:Hide() end
end

  • Upvote 1

Elite Cobra Squad

Link to comment
Share on other sites

@Rick

You can do the same with 1 script but you have to put this code into each script, duplicating the effort.

unless I have misunderstood you, If you use require you don't need to duplicate code, its kind of like an entity having mulitple scripts.

Elite Cobra Squad

Link to comment
Share on other sites

@beo6

However there is of course no wall/floor collsiontype. Only Scene

 

Yeah, that's what I was implying that in this instance being able to assign a collision type via the editor won't work to tell between wall/floor so that suggestion is off the table. Unless Josh gave us a way to add our own collision types that get exposed in the editor, which would be cool.

 

 

@josk

 

You can do a "require" to expose the field for a key/value but you need to actually set this to the entity. Which you would have to do in the Start() function of each script, which means you'd have to put code to set the key into each script. It may only be 1 line, but, and no offense to Andy as he's more of an art guy, people like Andy would benefit the most from this system and they don't know this stuff all that well, and in all honesty I hate code duplication so I wouldn't even like having to repeat this code in every script I need this functionality.

 

In the script you "require" there is no way to automatically assign the key/value that the user put into the editor to the entity. With multiple scripts we put that code inside it's own Script:Start() so it's done automatically and all the user has to do is attach the script and set the properties in the editor. No coding needed.

 

I actually made a request that setting/modifying entity keys for entities should be automatically included into the editor/engine which would help solve issues like this. I figured since key/value pairs are built into the engine the editor should support that functionality out of the box. Sounds reasonable to me smile.png

Link to comment
Share on other sites

I haven't tested, but I would "think" that they are created, but maybe they don't which makes it even worse smile.png. However you'd still need to set keys to the entity in question from the properties in the Script:Start() function so :-/ .

 

 

[EDIT]

I couldn't get it to work. I added to your FG_Button.lua at the top, require "Scripts/Cameras/3rdPersonFollow.lua", and it gave no errors but no target property showed up like the 3rdPersonFollow.lua file has.

 

These properties are all LE "magic" and I'm guessing Josh's code that creates the properties doesn't look at nested files.

Link to comment
Share on other sites

Hi, i seem to have this wokrnig great using

 

function Script:Collision(entity, position, normal, speed)
being = entity:GetKeyValue("name")
if being == "gobbo" then self.entity:Hide() end
end

 

But, what ive realised i want is to be able to detect collsion without collsion actually happeneing. As in, i have an object that moves and when it hits the "other" object i want to detect it touching it, but not actually stop and collide with it, (go through it!) Ive tryed make the collsion type to none, which makes the object no collide, but also make the collisionhook not work?

 

How could i do this?

 

Thanks

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

Have you tried collision type trigger?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Hi Josk, do you mean Nav obstacle? If so then that is unchecked. The collsion works fine, but like i said above i want to be able to go THROUGH the object but still pick up the collision hook.

 

I also have the static object as Prop, no mass.

 

Setting type as Trigger would do the trick IF is registered the collision callback, but it doesnt.

 

Thanks

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

Just had a look, if my character is a box built in the editor it stops, if its a model from an external source it goes through.

 

Set it to collision trigger it works. Basic code in the payer folder but working example.

Elite Cobra Squad

Link to comment
Share on other sites

Hmm there must be something going on then, as i still cant get the collision to register, the object is very simple so ive ceated a polymesh from it and loaded that in, when "show Physics" is enable it fits great, set to trigger and the object goes though, but no collision is registered?

 

Andy

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

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