Jump to content

Detect world object


Chupy

Recommended Posts

Hello, how can i detect an object near player? 

I want to make elements that is inside the wall invisible for players 

I put an object inside a wall, this object will be invisible and if the object is outside wall( normal world ) it will be visible

i tried use processLineOfSight it works but just in buildings, when i try in rocks,montains it doesnt work

 

 

Link to comment

It seems like you're asking two different questions here.

On 15/12/2022 at 14:40, Chupy said:

Hello, how can i detect an object near player?

If you want to detect actual collisions of the object (instead of just origin point of the object, which Spakye's post assumes) near the player, you could cast lines in several directions from the player and see if any of them detects an object. It may be sufficient if you just need to detect large objects (terrain, buildings), but not that reliable for smaller ones since collision checking lines are likely to miss the objects.

On 15/12/2022 at 14:40, Chupy said:

I want to make elements that is inside the wall invisible for players 

I put an object inside a wall, this object will be invisible and if the object is outside wall( normal world ) it will be visible

i tried use processLineOfSight it works but just in buildings, when i try in rocks,montains it doesnt work

What points do you pick for line of sight? Collisions mainly consist of boxes, spheres and meshes. For boxes and spheres (the former of which are used by some buildings), it can be objectively determined whether a point is "inside" or "outside", so perhaps if you cast some line from the object's position to some nearby point, the collision gets detected, which is why it happens to work for you with buildings. But objects of arbitrary shape use meshes, and there's no "inside" for meshes - a mesh is just a bunch of triangles put together to form a surface. When the line of sight crosses the surface, a collision is detected.

A primitive solution is to use getGroundPosition or getRoofPosition to check if there's anything above the point you're checking. But it will fail if there are ceilings.

Or you could choose several points on the "outside" so that at least one point would be visible from any place that is "outside". Then, whenever you want to check if some position is "outside", use processLineOfSight between that position and all of your chosen points. If at least one of them is visible from that position, that means it is "outside". This solution should be reliable, but manually choosing the visibility points beforehand means it will only work in that area. If the area you want to cover is large, that means lots of work (unless you make a script that automatically picks the points for you), plus you need to limit the number of points being checked because lots of processLineOfSight calls will be bad for performance.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...