Advertisement
Guest User

Bullet Synchro

a guest
Dec 30th, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. // BulletObject bullet here is a placeholder for the bullet being spawned, which has some
  2. // assumed properties and methods common to all bullets.
  3. void spawnBulletClientSide(BulletObject bullet, Vector3 pos, Vector2 velocity, float lag_time) {
  4.    // todo: add the bullet to the scene, this will vary by platform
  5.    // We will assume that we're passed a clone that just needs to be placed in the scene
  6.    // or that it is a class type and instantiated, leaving us with a reference to it
  7.    // which for simplicity I will simply refer to as the same bullet parameter passed to this method
  8.  
  9.    // place the bullet where it was spawned
  10.    bullet.position = pos;
  11.    // give it velocity
  12.    bullet.velocity = velocity;
  13.    // tell the bullet to execute its move() function for a time interval equal to the predicted lag time
  14.    // this
  15.    bullet.move(lag_time);
  16. }
  17.  
  18. /** BulletObject.move(float time) **/
  19.  
  20. void move(float time) {
  21.    if(this.hasGravity) {
  22.        pos += velocity * time + 0.5 * gravity_accel * time * time;
  23.    }
  24.    else {
  25.       pos += velocity * time;
  26.    }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement