I have parsed some data on grenade throws from the videogame Counter Strike. The sample data beloew reveals that I have positions on where the grenade is thrown from and where the grenade detonates and when the grenade is thrown.
df <- data.frame(pos_x = c(443.6699994744587,459.4566921116250, 443.5131582404877, 565.8823313012402, 725.3048665125078, 437.3428992800084, 475.7286794460795, 591.4138769182258),
pos_y = c(595.8564633895517, 469.8560006170301, 558.8543552036199, 390.5840189222542, 674.7983854380914, 688.0909476552858, 468.4987145207733, 264.6016042780749),
plot_group = c(1, 1, 2, 2, 3, 3, 4, 4),
round_throw_time = c(31.734375, 31.734375, 24.843750, 24.843750, 35.281250, 35.281250, 30.437500, 30.437500),
pos_type = c("Player position", "HE detonate", "Player position", "HE detonate", "Player position", "HE detonate", "Player position", "HE detonate"))
And using ggplot2 I can plot the static trajectories of the grenades like shown here
But I would like to animate the grenade trajectories and iniate the animation of each trajectory in the order that round_throw_time
prescribes it and moving from player position to detonate position.
So far I have attempted this:
ggplot(df, aes(pos_x, pos_y, group = plot_group)) +
annotation_custom(grid::rasterGrob(img, width = unit(1,"npc"), height =
unit(1,"npc")), 0, w, 0, -h) +
scale_x_continuous(expand = c(0,0),limits = c(0,w)) +
scale_y_reverse(expand = c(0,0),limits = c(h,0)) +
geom_point(color = "red") +
transition_states(states=pos_type, transition_length = 1, state_length = 1)
But I'm kinda lost when it comes to adding the trajectory lines and how to reset the animation instead of the point just moving back to their origin.
Any tips would be greatly appreciated!
The image I plot onto can be downloaded here http://simpleradar.com/downloads/infernoV2.zip