public void SyncDataToObj(List <object> objs, float timeDiff) { lastPos = position; currentFixedTime = 0; DataConverter.ApplyFieldsToInstance(this, objs); FlipSprite(leftDirection); }
public void SyncDataToObj(List <object> objs, float timeDiff) { DataConverter.ApplyFieldsToInstance(this, objs); // Set host when it is flagged if (isHost) { MultiplayerManager.peerManager.SetHost(this); } }
public void SyncDataToObj(List <object> objs, float timeDiff) { prevPos = position; prevRotation = rotation; currentTime = 0; DataConverter.ApplyFieldsToInstance(this, objs); Vector2 curVelocity = (position - prevPos) / PhysicsManager.PHYSICS_UPDATE_INTERVAL; float acceleration = curVelocity.magnitude - prevVelocity.magnitude; // New position based on the time it took to calculate the physics on the host Vector2 calculatedPos = position + curVelocity * (timeDiff * 2 + PhysicsManager.PHYSICS_UPDATE_INTERVAL); // Caclulate how accruate the prediction needs to be for it to trigger a authoritive state change accuracyValue = curVelocity.magnitude + 0.01f; if (acceleration > -0.05f) { accuracyValue += Mathf.Clamp(accelerationThreshold - acceleration, 0, accelerationThreshold); } // Set the state change if the local state deviates too much from the host's state if (Vector2.Distance(position, transform.position) > accuracyValue && Vector2.Distance(calculatedPos, transform.position) > accuracyValue ) { rb.MovePosition(Vector2.MoveTowards(position, transform.position, Time.fixedDeltaTime)); rb.velocity = velocity; } // Set rotation for static objects if (Mathf.Abs(prevRotation - rotation) > accuracyValue) { transform.rotation = Quaternion.Euler(0, 0, rotation); } prevVelocity = curVelocity; }
public void SyncDataToObj(List <object> objs, float timeDiff) { DataConverter.ApplyFieldsToInstance(this, objs); }
// Recieve a projectile and sync it up based on the timediff public void SyncDataToObj(List <object> objs, float timeDiff) { DataConverter.ApplyFieldsToInstance(this, objs); position += direction * (speed * timeDiff); SetTransform(); }