@@ -15,25 +15,25 @@ import (
1515type Player struct {
1616 demoInfoProvider demoInfoProvider // provider for demo info such as tick-rate or current tick
1717
18- SteamID64 uint64 // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID
19- LastAlivePosition r3.Vector // The location where the player was last alive. Should be equal to Position if the player is still alive.
20- UserID int // Mostly used in game-events to address this player
21- Name string // Steam / in-game user name
22- Inventory map [int ]* Equipment // All weapons / equipment the player is currently carrying. See also Weapons().
23- AmmoLeft [32 ]int // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType
24- EntityID int // Usually the same as Entity.ID() but may be different between player death and re-spawn.
25- Entity st.Entity // May be nil between player-death and re-spawn
26- FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds)
27- FlashTick int // In-game tick at which the player was last flashed
28- TeamState * TeamState // When keeping the reference make sure you notice when the player changes teams
29- Team Team // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists).
30- IsBot bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot().
31- IsConnected bool
32- IsDefusing bool
33- IsPlanting bool
34- IsReloading bool
35- IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162
36- LastPositions [] r3.Vector // CS2 only, used to compute velocity as it's not networked in CS2 demos
18+ SteamID64 uint64 // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID
19+ LastAlivePosition r3.Vector // The location where the player was last alive. Should be equal to Position if the player is still alive.
20+ UserID int // Mostly used in game-events to address this player
21+ Name string // Steam / in-game user name
22+ Inventory map [int ]* Equipment // All weapons / equipment the player is currently carrying. See also Weapons().
23+ AmmoLeft [32 ]int // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType
24+ EntityID int // Usually the same as Entity.ID() but may be different between player death and re-spawn.
25+ Entity st.Entity // May be nil between player-death and re-spawn
26+ FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds)
27+ FlashTick int // In-game tick at which the player was last flashed
28+ TeamState * TeamState // When keeping the reference make sure you notice when the player changes teams
29+ Team Team // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists).
30+ IsBot bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot().
31+ IsConnected bool
32+ IsDefusing bool
33+ IsPlanting bool
34+ IsReloading bool
35+ IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162
36+ PreviousFramePosition r3.Vector // CS2 only, used to compute velocity as it's not networked in CS2 demos
3737}
3838
3939func (p * Player ) PlayerPawnEntity () st.Entity {
@@ -522,12 +522,8 @@ func (p *Player) PositionEyes() r3.Vector {
522522// Velocity returns the player's velocity.
523523func (p * Player ) Velocity () r3.Vector {
524524 if p .demoInfoProvider .IsSource2 () {
525- if ! p .IsAlive () || len (p .LastPositions ) != 2 {
526- return r3.Vector {}
527- }
528-
529525 t := 64.0
530- diff := p .LastPositions [ 1 ] .Sub (p .LastPositions [ 0 ] )
526+ diff := p .Position () .Sub (p .PreviousFramePosition )
531527
532528 return r3.Vector {
533529 X : diff .X * t ,
@@ -813,9 +809,9 @@ type demoInfoProvider interface {
813809// Intended for internal use only.
814810func NewPlayer (demoInfoProvider demoInfoProvider ) * Player {
815811 return & Player {
816- Inventory : make (map [int ]* Equipment ),
817- demoInfoProvider : demoInfoProvider ,
818- LastAlivePosition : r3.Vector {},
812+ Inventory : make (map [int ]* Equipment ),
813+ demoInfoProvider : demoInfoProvider ,
814+ PreviousFramePosition : r3.Vector {},
819815 }
820816}
821817
0 commit comments