How do I avoid players jumping around in a multiplayer game?

Not favoritedFavorited Favorited 0 favourites
  • 1 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • I am adding multiplayer and am using the real time example project as a guide. However while it's mostly smooth peers still get a jitter when they stop moving as they align with the host. peer inputs follow the example and are a bit variable only updated on network updates. So I am not sure what is going on. I have included a stripped down project if anyone would be able to help.

    Function that sets the input

    * On function 'setInputState' (copy picked)
    ----+ Keyboard: W is down
    -----> playerRep: Set INPUT_booleans to setbit(Self.INPUT_booleans,0,1)
    
    ----+ System: Else
    -----> playerRep: Set INPUT_booleans to setbit(Self.INPUT_booleans,0,0)
    
    ----+ Keyboard: S is down
    -----> playerRep: Set INPUT_booleans to setbit(Self.INPUT_booleans,1,1)
    
    ----+ System: Else
    -----> playerRep: Set INPUT_booleans to setbit(Self.INPUT_booleans,1,0)
    
    ----+ Keyboard: A is down
    -----> playerRep: Set INPUT_booleans to setbit(Self.INPUT_booleans,3,1)
    
    ----+ System: Else
    -----> playerRep: Set INPUT_booleans to setbit(Self.INPUT_booleans,3,0)
    
    ----+ Keyboard: D is down
    -----> playerRep: Set INPUT_booleans to setbit(Self.INPUT_booleans,4,1)
    
    ----+ System: Else
    -----> playerRep: Set INPUT_booleans to setbit(Self.INPUT_booleans,4,0)
    
     // Looking angle is copied to our player. 
    ----+ (no conditions)
    -----> playerRep: Set lookingAngleX to myDesiredAngle
    

    Function that applies the inputs (Taken from the Ghost Capture example)

    * On function 'apply inputs' (copy picked)
     // apply movement
     | Local number moveSpeed‎ = 1
     // Whether or not the player is trying to move left.
     | Local number MoveLeft‎ = 0
     // Whether or not the player is trying to move right.
     | Local number MoveRight‎ = 0
     // Whether or not the player is trying to move up.
     | Local number MoveUp‎ = 0
     // Whether or not the player is trying to move down.
     | Local number MoveDown‎ = 0
     // Reset all movement variables back to zero.
    ----+ (no conditions)
    -----> System: Set MoveLeft to 0
    -----> System: Set MoveRight to 0
    -----> System: Set MoveUp to 0
    -----> System: Set MoveDown to 0
    
     // If the player is pressing A, set the move left variable to one.
    ----+ System: getbit(playerRep.INPUT_booleans,0) = 1
    -----> System: Set MoveUp to 1
    
     // If the player is pressing D, set the move right variable to one.
    ----+ System: getbit(playerRep.INPUT_booleans,1) = 1
    -----> System: Set MoveDown to 1
    
     // If the player is pressing W, set the move up variable to one.
    ----+ System: getbit(playerRep.INPUT_booleans,3) = 1
    -----> System: Set MoveLeft to 1
    
     // If the player is pressing S, set the move down variable to one.
    ----+ System: getbit(playerRep.INPUT_booleans,4) = 1
    -----> System: Set MoveRight to 1
    
     // To which direction the player is trying to move to horizontally.
     | Local number HorizontalAxis‎ = 0
     // To which direction the player is trying to move to vertically.
     | Local number VerticalAxis‎ = 0
     // A general angle based on both horizontal and vertical axis.
     | Local number AxisAngle‎ = 0
     // Calculate the general direction at which the player is trying to move to.
    ----+ System: Every tick
    -----> System: Set HorizontalAxis to MoveRight - MoveLeft
    -----> System: Set VerticalAxis to MoveDown - MoveUp
    -----> System: Set AxisAngle to angle(0, 0, HorizontalAxis, VerticalAxis)
    
     // The final angle of motion for the player.
     | Local number MovementAngle‎ = 0
     // If the player is trying to move to any direction and the game status is set to "Playing", calculate the player's movement angle.
    ----+ System: HorizontalAxis <> 0 | VerticalAxis <> 0
    -----> System: Set MovementAngle to playerRep.LookingAngleX + AxisAngle + 90
     // I tried to move by whole steps instead of allowing delta time to influence the movement. that did not resolve the issue 
    --------+ (no conditions)
    ---------> playerRep: Set X to Self.X + cos(MovementAngle) × moveSpeed
    ---------> [DISABLED] playerRep: Set X to Self.X + cos(MovementAngle) × moveSpeed × 60 × dt
    ------------+ playerRep: Is overlapping wallObject
    ----------------+ System: While
    ----------------+ playerRep: Is overlapping wallObject
    -----------------> playerRep: Set X to Self.X + cos(MovementAngle + 180) × 0.1
    
     // I tried to move by whole steps instead of allowing delta time to influence the movement. that did not resolve the issue 
    --------+ (no conditions)
    ---------> playerRep: Set Y to Self.Y + sin(MovementAngle) × moveSpeed
    ---------> [DISABLED] playerRep: Set Y to Self.Y + sin(MovementAngle) × moveSpeed × 60 × dt
    ------------+ playerRep: Is overlapping wallObject
    ----------------+ System: While
    ----------------+ playerRep: Is overlapping wallObject
    -----------------> playerRep: Set Y to Self.Y + sin(MovementAngle + 180) × 0.1
    

    Host group

    + playerRep: peerID ≠ myPeerID
    + System: For each playerRep
    -> playerRep: Set lookingAngleX to Multiplayer.PeerState(playerRep.peerid, "inputLookX")
    -> playerRep: Set INPUT_booleans to Multiplayer.PeerState(playerRep.peerid, "inputBool")
    -> Functions: Call apply inputs
    
    + playerRep: peerID = myPeerID
    -> Functions: Call setInputState
    -> Functions: Call apply inputs
    

    Peer group

    + Multiplayer: On client update
    + playerRep: peerID = myPeerID
    -> Functions: Call setInputState
    -> Multiplayer: Set client input state "inputBool" to value playerRep.INPUT_booleans
    -> Multiplayer: Set client input state "inputLookX" to value playerRep.lookingAngleX
    
    + playerRep: peerID = myPeerID
    -> Functions: Call apply inputs
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)