#Predicted movement for projectiles

28 messages · Page 1 of 1 (latest)

young sapphire
#

I'm trying to make projectiles that use predicted spawning, but when they spawn, they don't move for a little bit until the server initializes them and tells them to move. I'd like to be able to predictively move them on the client while still having them be server-authoritative, similar to how CSP for player movement works with FishNet.

I tried using Replicate and Reconcile, but I only need to call the Replicate method once to apply the initial force to the projectile, and that seems to cause problems with the movement. The projectiles just stop moving after a bit. I am aware of the guide in the docs about projectile lag compensation, but that method doesn't really allow for reconciliation, which is necessary in my game since projectiles can change directions unpredictably. Is there a way to use Replicate and Reconcile for projectiles the same way they can be used for player movement?

rough steppe
# broken grove You're using P2?

Hi! I use Prediction V2 for projectiles and it works stable. But the projectile still spawns on the server. I'm thinking of using Predicted Spawn to have the projectile spawn on the client, but that could potentially be a weakness for cheating, right? It's just that as far as I understand it, I can't make a check on the server when a projectile is spawned, whether the client can shoot or not.

broken grove
#

You can use predictedspawn and use read/sendPayload to send custom data with the spawn if you like. Server can validate everything by inheriting predictedspawn and using your own logic as needed.

#

Server can reject or accept the spawn

rough steppe
young sapphire
# broken grove You're using P2?

Yes, I followed the guide for non-controlled objects and got fairly close, but I still had problems with projectiles spawning in front of or behind where they should sometimes.

broken grove
#

They are probably reconciling and velocity isn't being reapplied. @young sapphire

young sapphire
# broken grove They are probably reconciling and velocity isn't being reapplied. <@264210234132...

How could I fix that, and when should I apply the initial velocity? I've tried doing it OnStartServer, but that makes it not move immediately on the client. I've also tried OnStartNetwork but the projectile moves way faster on the local client than the host for some reason. I think I fixed that back when I made this post, but I don't remember how. Here's a script of a basic projectile I made: https://hatebin.com/dbgpkznzfu

young sapphire
#

@broken grove I fixed the speed difference, but I'm still not sure how to fix the reconcile thing that causes projectiles to spawn in front of or behind where they're supposed to. I might not use predicted spawning since I want everything to be 100% synced, but I'd still like to use movement prediction just to have the physics of the projectiles replicated across clients.

broken grove
#

@young sapphire it might be happening because predictedspawns send immediately while csp goes into a tick queue. There's a lot of plans to better a huge majority of this after the 'big thing' being worked on is done. How are you spawning it? Update, replicate, and how are you setting transform values

young sapphire
# broken grove <@264210234132791296> it might be happening because predictedspawns send immedia...

The movement script for the projectile itself is here: https://hatebin.com/dbgpkznzfu
I'm just setting the the velocity in OnStartNetwork, not updating any transforms manually. As for spawning, I'm calling the spawn method on the client in update. But even when I stop using predicted spawning so it should theoretically be spawning in line with the ticks, it still often spawns behind or ahead of where it should in its trajectory line.

broken grove
#

@young sapphire ticks are queued so it's most likely spawning before the input is run. Need to see exact spawn code though

young sapphire
# broken grove <@264210234132791296> ticks are queued so it's most likely spawning before the i...

The spawn is just a simple input check in Update and then pulling it from the pool. Here's the snippet of code

[Client(RequireOwnership = true)]
void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        PoolSpawn();
    }
}    
private void PoolSpawn()
{
    NetworkObject nob = NetworkManager.GetPooledInstantiated(projectilePrefab, firePoint.position, firePoint.rotation, IsServerStarted);
    ServerManager.Spawn(nob);
}
#

I see how that would be problematic for predicted spawning but I'm not sure why it happens even if I spawn it normally.

#

It's doing that even without predicted spawning, just spawning normally and using OnStartNetwork and reconcile to sync movement instead of network transform

young sapphire
#

I just tested it without pooling and it fixed the problem, so it's something to do with the pooling not resetting the properties properly or something. I tried setting the velocity to zero on despawn but it didn't fix it, so I'm not sure.

young sapphire
#

It looks like just the graphical object is behind, the actual projectile itself is where it should be, so it must be something with the interpolation or graphical object displacement being more and more the more times it pools and unpools for some reason.

#

Resetting the graphical object's local position to zero whenever it spawns fixed it, but I'm not sure what's causing it in the first place.

#

Also doing that only fixed it for the server for some reason, it's still a problem on the clients.

thin musk
#

They already merged my fix for this problem but it isn’t released yet

#

You can just apply the same simple fix yourself

young sapphire
young sapphire
#

I just implemented it and it looks like it works

broken grove