Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add suport for triggers on entities #223

Closed
wants to merge 1 commit into from
Closed

Conversation

Flowtter
Copy link
Contributor

This pull requests depends on #222

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

2022-11-25.16-00-34.mp4

@Flowtter Flowtter force-pushed the trigger branch 3 times, most recently from 640bf99 to 3bba303 Compare November 30, 2022 09:15
@Donorhan
Copy link
Contributor

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
Copy link
Contributor Author

Flowtter commented Dec 1, 2022

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
Copy link
Contributor

Donorhan commented Dec 1, 2022

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 Flowtter marked this pull request as draft December 1, 2022 10:25
@Flowtter
Copy link
Contributor Author

Flowtter commented Dec 1, 2022

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

@Flowtter Flowtter closed this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants