I've been trying to make a script that allows you to rewind the game. It correctly sets the positions of the joints and bodyparts, but not the orientation of the bodyparts. I've tried using get_body_info(player,part).sides, but this function always returns the same answer, no matter what the orientation is.
Also if I use set_body_sides with different data it causes toribash to crash.
-- replay_rewind
do
local joint_poss = {} -- done
local body_infos = {}
local grip_states = {}
local body_infos = {} -- doing
local body
local body_angular_vels = {}
local nody_linear_vels = {}
local current_frame = 1
local function enter_frame()
world_state = get_world_state()
match_frame = world_state.match_frame
joint_poss[match_frame] = {}
body_infos[match_frame] = {}
echo("match_frame = "..match_frame)
for p=0,1,1 do
joint_poss[match_frame][p] = {}
body_infos[match_frame][p] = {}
for temp,j in pairs(JOINTS) do
x,y,z=get_joint_pos(p,j)
joint_poss[match_frame][p][j] = {x,y,z}
end
for temp,j in pairs(BODYPARTS) do
body_infos[match_frame][p][j] = get_body_info(p,j)
end
end
end
local function set_tori()
if joint_poss[current_frame]==nil then
echo ("current frame does not exist")
else
for p=0,1,1 do
for temp,j in pairs(JOINTS) do
jp = joint_poss[current_frame][p][j]
echo ("p="..p.." j="..j.." jp[1]="..jp[1])
set_joint_pos(p, j, jp[1], jp[2], jp[3])
end
for temp,j in pairs(BODYPARTS) do
bp = body_infos[current_frame][p][j].pos
set_body_pos(p,j, bp.x, bp.y, bp.z)
bs = body_infos[current_frame][p][j].sides
set_body_sides(p,j, bs.x, bs.y, bs.z)
end
end
end
end
local function key_down(key)
if key==string.byte('[') then
current_frame = current_frame - 1
echo ("current_frame = "..current_frame)
set_tori()
return 1
end
if key==string.byte(']') then
current_frame = current_frame + 1
echo ("current_frame = "..current_frame)
set_tori()
return 1
end
end
add_hook("enter_frame","replay_rewind", enter_frame)
add_hook("key_down", "replay_rewind", key_down)
end