- Home /
Question by
ZhavShaw · Sep 29, 2017 at 02:01 AM ·
multiplayershootingmultiplayer-networkinglagfire
Lag Compensated Projectile
First of all I just wanted to say thank you for taking the time out to read this.
So I'm having a problem as to how I could create Lag Compensated Projectiles. The system I have is setup to send the frame of the server on which we fire, and it can rewind the hitboxes back up to 60 frames (1 second).
I'm not quite sure how exactly I should go about compensating for the lag.
What I have for my projectile script is this:
public float speed = 10;
public float gravity = -9;
public Vector3 oldPos;
public Vector3 newPos;
Vector3 direction;
Vector3 velocity;
Vector3 force;
float distance;
RaycastHit hit;
if (Physics.Raycast(oldPos, direction, out hit, distance, ~ignoreLayers))
{
// we hit an object
Destroy(gameObject);
}
else
{
// set our previos position and move bullet
oldPos = transform.position;
transform.position = newPos;
}
Comment