@@ -15,24 +15,25 @@ import (
15
15
type Player struct {
16
16
demoInfoProvider demoInfoProvider // provider for demo info such as tick-rate or current tick
17
17
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
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
36
37
}
37
38
38
39
func (p * Player ) PlayerPawnEntity () st.Entity {
@@ -521,7 +522,14 @@ func (p *Player) PositionEyes() r3.Vector {
521
522
// Velocity returns the player's velocity.
522
523
func (p * Player ) Velocity () r3.Vector {
523
524
if p .demoInfoProvider .IsSource2 () {
524
- panic ("Velocity() is not supported for Source 2 demos" )
525
+ t := 64.0
526
+ diff := p .Position ().Sub (p .PreviousFramePosition )
527
+
528
+ return r3.Vector {
529
+ X : diff .X * t ,
530
+ Y : diff .Y * t ,
531
+ Z : diff .Z * t ,
532
+ }
525
533
}
526
534
527
535
if p .Entity == nil {
@@ -801,8 +809,9 @@ type demoInfoProvider interface {
801
809
// Intended for internal use only.
802
810
func NewPlayer (demoInfoProvider demoInfoProvider ) * Player {
803
811
return & Player {
804
- Inventory : make (map [int ]* Equipment ),
805
- demoInfoProvider : demoInfoProvider ,
812
+ Inventory : make (map [int ]* Equipment ),
813
+ demoInfoProvider : demoInfoProvider ,
814
+ PreviousFramePosition : r3.Vector {},
806
815
}
807
816
}
808
817
0 commit comments