I’m working on a Space game that relies heavily on client loaded assets etc.
Reason for this being; its a Space exploration game and each Planet is essentially an “Instance” of their own.
When a Player loads a Planet, they unload space. Etc.
I’m trying to make this work for Hostiles, so that Players have more sense of interaction when trying to level up.
Though, I’ve ran into an issue - As the Map is loaded on the client for each Player, this means the hostile can be in two different positions - Making it seem as if a Player is fighting literally nothing and sort of ruining the immersion.
What is a way I can allow for Client Sided Hostiles that are replicated across all Players present on the planet?
Brief example of a concept in the past:
I would manage this Server Sided, checking the magnitude of Players and if any were in the proximity.
If so, Hostile would spawn and the Ownership would be set to the nearest Player, therefore stopping it from falling through the floor of the Client loaded Planet.
I’m not to familiar with these kinds of stuff but I suggest the Ownership should be on the server. To make it not fall through the map, you could make the planets be loaded in the server side and when a player joins, they would delete all planets and when a hostile spawns, a player script would detect that and delete it if they are not on the same planet with that hostile. Deleting the hostiles might take up performance depending on the amount spawning and how complex the hostile model is. To reduce that, I suggest making a folder on each planet that holds all the hostiles so a localScript would just detect if a new child was added on there and delete it. You could use game:GetService(“Debris”). It another form of object deletion but they don’t delete immediately and it might improve performance but I’m not too sure.
If you want the hostile to spawn on the server but only be replicated to players on the same planet (instead of all the players), you could use this thingy I found:
I’m not too sure how it works or how good it is (as I never used it) but it basically allows you to replicate things from the server to some clients instead of all of them.
If you really want the hostiles to be client-sided, you could:
Use a remote event to send the position of the hostile to the server and the server will take that position and send it to the other players on the same planet. You could send the position every 10-20 times, just remember to not send to much data as not all players have good connection. You should also make latency compensation so that the hostile don’t look like it just teleporting to positions. This is quite hard to do.
If one hostile spawns, make duplicates of it for each player and set each Ownership to each player. Then, make the duplicates of other hostiles not meant for a player to be invisible for that player. The immersion only breaks when one players has high ping so they might have a hostile chasing them while for an other player that hostile is chasing them.
Try experimenting with NetworkOwnership. NetworkOwnership of physics-based parts get replicated easily to the server and other players. Not too sure if the same case work for Humanoids but it worth a shot.