Skip to content

Commit 5b974d7

Browse files
authored
common: add GrenadeProjectile.Velocity() function (#286)
1 parent 9190856 commit 5b974d7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/demoinfocs/common/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func (g *GrenadeProjectile) Position() r3.Vector {
7979
return g.Entity.Position()
8080
}
8181

82+
// Velocity returns the projectile's velocity.
83+
func (g *GrenadeProjectile) Velocity() r3.Vector {
84+
return g.Entity.PropertyValueMust("m_vecVelocity").VectorVal
85+
}
86+
8287
// UniqueID returns the unique id of the grenade.
8388
// The unique id is a random int generated internally by this library and can be used to differentiate
8489
// grenades from each other. This is needed because demo-files reuse entity ids.

pkg/demoinfocs/common/common_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ func TestGrenadeProjectileUniqueID(t *testing.T) {
3232
assert.NotEqual(t, NewGrenadeProjectile().UniqueID(), NewGrenadeProjectile().UniqueID(), "UniqueIDs of different grenade projectiles should be different")
3333
}
3434

35+
func TestGrenadeProjectile_Velocity(t *testing.T) {
36+
expected := r3.Vector{
37+
X: 1,
38+
Y: 2,
39+
Z: 3,
40+
}
41+
42+
p := GrenadeProjectile{
43+
Entity: entityWithProperty("m_vecVelocity", st.PropertyValue{VectorVal: expected}),
44+
}
45+
46+
assert.Equal(t, expected, p.Velocity())
47+
}
48+
3549
func TestDemoHeader(t *testing.T) {
3650
header := DemoHeader{
3751
PlaybackFrames: 256,

0 commit comments

Comments
 (0)