Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Lag Compensated Projectiles

$
0
0
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; private void FixedUpdate() { velocity = speed * transform.forward + force; force += new Vector3(0, gravity, 0); newPos += velocity * Time.deltaTime; direction = newPos - oldPos; distance = direction.magnitude; RaycastHit hit; if (Physics.Raycast(oldPos, direction, out hit, distance, ~ignoreLayers)) { Destroy(gameObject); } else { oldPos = transform.position; transform.position = newPos; } } All it really does is move a transform and cast a ray from the previous position to the current position and adds gravity.

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>