BoltNetwork.Instantiate?

Options
If I call BoltNetwork.Instantiate on a client, I am seeing the object created on that client and the server, but not on the peers. I am using manual scoping and immediately call SetScopeAll(true) on the next line.

Is that expected behaviour? I'd like the object to also be created on peers

Best Answer

Answers

  • Modaz
    Options
    Thanks for the response. So, imagine a slow moving projectile. If I wanted a client to create it so that everyone can see it, I have the options:

    - Event to server from the client, server instantiates projectile to all

    Downside to this option is round-trip latency player will experience before seeing object created.
    Another way:

    - Client instantiates (controlling player sees immediate response), then event to server, then server instantiates, then scope to all except original client.

    Is this last option the best way to achieve what I'm going for?
  • Yukichu
    Yukichu
    edited February 2016
    Options
    While I haven't done this yet, I've thought about it. When you send the slow-moving object event to the server to instantiate it, send what frame it was created, and/or what frame it is going to detonate (if it's any sort of random, otherwise everyone can just calculate the end-frame the same way.)

    Yeah, I'd probably have the client create their own copy immediately, or 'trick' them with the old 'you have to charge up before you do your attack'.

    When it's created for the peers, you can lerp it to where it should be in the trajectory/animation/whatever since you know the frame it was supposed to be created, and synchronize the detonation with the frame it will explode, since all clients should be on the same frame.
  • hvault
    hvault
    edited February 2016
    Options
    I do just about what Yukichu said for projectiles and it works well, but everything is sever only (no client only copies).
    Each event has the server frame, origin, direction, and ID of the projectile.
    I use the ID to lookup the prefab, speed, etc....

    Then have a function which works out the projectiles position based on that data.
    I've seen little to no issues so far with latency, but if the lag is high and projectiles fast they may appear to not fire the first few initial frames, but they will always be in the correct spot once they appear.

    To calculate the position, use something like this:
            private Vector3 GetPositionAtFrame(int frame)
            {
                int totalDelta = frame - this.spawnFrame;
                return this.origin + (this.velocity * BoltNetwork.frameDeltaTime * totalDelta);
            }
    And in fixed update this:
    this.transform.position = this.GetPositionAtFrame(BoltNetwork.serverFrame);
  • bigd
    Options
    This is interesting. We're currently struggling with how to make networked projectiles and the syncing issues.

    I'm curious if there's a working example of this concept we can inspect?
  • hvault
    Options
    I'll see if I can find the time over the next week to write up some info that may give you a hand. Might not be until the weekend.