public override void SetLocation( LocationUpdate update, bool interpolate ) { Vector3 lastPos = serverPos; float lastYaw = serverYaw, lastPitch = serverPitch; if( update.IncludesPosition ) { serverPos = update.RelativePosition ? serverPos + update.Pos : update.Pos; } if( update.IncludesOrientation ) { serverYaw = update.Yaw; serverPitch = update.Pitch; } if( !interpolate ) { stateCount = 0; newState = oldState = new State( tickCount, serverPos, serverYaw, serverPitch ); } else { // Smoother interpolation by also adding midpoint. Vector3 midPos = Vector3.Lerp( lastPos, serverPos, 0.5f ); float midYaw = Utils.InterpAngle( lastYaw, serverYaw, 0.5f ); float midPitch = Utils.InterpAngle( lastPitch, serverPitch, 0.5f ); AddState( new State( tickCount, midPos, midYaw, midPitch ) ); AddState( new State( tickCount, serverPos, serverYaw, serverPitch ) ); } }
public override void SetLocation( LocationUpdate update, bool interpolate ) { if( update.IncludesPosition ) { nextPos = update.RelativePosition ? nextPos + update.Pos : update.Pos; nextPos.Y += Entity.Adjustment; if( !interpolate ) { lastPos = Position = nextPos; } } if( update.IncludesOrientation ) { nextYaw = update.Yaw; nextPitch = update.Pitch; if( !interpolate ) { lastYaw = YawDegrees = nextYaw; lastPitch = PitchDegrees = nextPitch; } } }
void UpdateLocation( byte playerId, LocationUpdate update, bool interpolate ) { Player player = game.Players[playerId]; if( player != null ) { player.SetLocation( update, interpolate ); } }
public abstract void SetLocation( LocationUpdate update, bool interpolate );
public abstract void SetLocation(LocationUpdate update, bool interpolate);
internal bool HandleKeyDown(Key key) { KeyMap keys = game.InputHandler.Keys; if (key == keys[KeyBinding.Respawn] && Hacks.CanRespawn) { Vector3I p = Vector3I.Floor(SpawnPoint); if (game.Map.IsValidPos(p)) { // Spawn player at highest valid position. for (int y = p.Y; y <= game.Map.Height; y++) { byte block1 = physics.GetPhysicsBlockId(p.X, y, p.Z); byte block2 = physics.GetPhysicsBlockId(p.X, y + 1, p.Z); if (info.CollideType[block1] != BlockCollideType.Solid && info.CollideType[block2] != BlockCollideType.Solid) { p.Y = y; break; } } } Vector3 spawn = (Vector3)p + new Vector3(0.5f, 0.01f, 0.5f); LocationUpdate update = LocationUpdate.MakePosAndOri(spawn, SpawnYaw, SpawnPitch, false); SetLocation(update, false); } else if (key == keys[KeyBinding.SetSpawn] && Hacks.CanRespawn) { SpawnPoint = Position; SpawnYaw = HeadYawDegrees; SpawnPitch = PitchDegrees; } else if (key == keys[KeyBinding.Fly] && Hacks.CanFly && Hacks.Enabled) { flying = !flying; } else if (key == keys[KeyBinding.NoClip] && Hacks.CanNoclip && Hacks.Enabled) { if (noClip) { Velocity.Y = 0; } noClip = !noClip; } else if (key == keys[KeyBinding.Jump] && !onGround && !(flying || noClip)) { if (!firstJump && Hacks.CanDoubleJump && Hacks.DoubleJump) { DoNormalJump(); firstJump = true; } else if (!secondJump && Hacks.CanDoubleJump && Hacks.DoubleJump) { DoNormalJump(); secondJump = true; } } else { return(false); } return(true); }