l3mpire / lemverse

The first-ever coworking metaverse
https://app.lemverse.com
GNU Affero General Public License v3.0
148 stars 40 forks source link

Add suport for triggers on entities #223

Closed Flowtter closed 1 month ago

Flowtter commented 1 year ago

This pull requests depends on https://github.com/l3mpire/lemverse/pull/222

It allows us to create a new type of collider, the "triggers" which enable actions when you enter the zone.

https://user-images.githubusercontent.com/34689945/204011594-bfee6d47-0cf3-4505-878b-800584f87e59.mp4

Donorhan commented 1 year ago

I don't understand the need, that's the purpose of zones to be able to trigger actions when you enter them 🤔. Entities are useful for interacting, zones are useful for triggering actions.

The best thing, in my opinion, is to be able to change the state of an entity when a user enters or exits a zone.

Flowtter commented 1 year ago

I believe it should be the opposite, as in, an Entity (seen as GameObject), should have its own own logic and not depends on another one unless it is necessary. Popular engines are using this logic, unity, unreal and so on.

I like the idea that a/many zone.s could change the state of one/many Entity.ies, but i think this would be a totally different feature.

As for the need, we're trying to trigger animations only when you enter an area, so yeah a zone could indeed do the job, but as stated, I think those should be two differents features requests.

Donorhan commented 1 year ago

I agree with you that an entity should be independent from the rest and handle it all by itself. Unity and Unreal are more or less based on a component entity system, which Phaser does not manage in its version 3.

Phaser's sensor system is very limited, the physics engine used is very basic so you can't rely on it either.

The solution you have implemented makes the code more complex and browsing each entity will increase the CPU load exponentially, especially since this logic of managing close entities already exists in the code (to display pop-ins).

What I can suggest is to add an event when the closest entity changes. To do that you should modify the entity-manager.js file and send events in handleNearestEntityTooltip of this type onClosestEntityChanged(nearestEntity, previousNearestEntity, distance). On the other hand it is a simple proximity detection, only in relation to a distance, no polygons.

Currently the detection is "raw" because the need is not 5000 entities per level, we can later use binary trees or quadtrees.

Flowtter commented 1 year ago

I did not use the nearest entity since I wanted the user to be able to interract with multiple triggers at the same time.

I agree with CPU load though