I am kinda new at LUA scripting, and I cannot figure out why my angle math isn't working. I would appreciate some help.
The script is for Bugs Bunny Lost In Time on PSX, gameID SLUS-00838.
The game maps the word so that 0,0,0 is in a corner, so I cannot rely on the position to get a proper angle, I figured using the speed values would also work, but it seems that it doesn't, because according to that, I never steer away more than 3 degrees from "straight forward".
Can someone please explain what I am doing wrong?
Script:
Language: lua
--position, speed and direction
local Xpos
local XposOld = 0
local Ypos
local YposOld = 0
local Zpos
local ZposOld = 0
local Xspeed = 0
local Yspeed = 0
local Zspeed = 0
--not really a need to look at Y-speed as it seems to be independent of XZ speed, might still be useful for jumping.
local XZspeed
local XZdirection = 0
--stats
local health
local inlvlCarrots
local inlvlGoldenCarrots
local inlvlClocks
local inlvlACME
local totalCarrots
local totalGoldenCarrots
local totalClocks
local abilities
local jump = false
local music = false
local sesame = false
local fan = false
local function hud()
--Actual speed vector addresses, not very good as they show speed even when you're blocked by a wall etc.
--addr 00069D30 X Speed [signed word]
--addr 00069D34 Y Speed(?) [signed word]
--addr 00069D38 Z Speed [signed word]
Xpos = memory.readdwordsigned(0x00069DC0)
Ypos = memory.readdwordsigned(0x00069DC4)
Zpos = memory.readdwordsigned(0x00069DC8)
--will not show the proper speed on the first frame of a level
--the game only runs at 30 fps.
local tempXspeed = Xpos - XposOld
local tempYspeed = Ypos - YposOld
local tempZspeed = Zpos - ZposOld
local tempXZdirection = math.atan2(tempZspeed, tempXspeed)
if tempXspeed ~= 0 or tempYspeed ~= 0 or tempZspeed ~= 0 then
Xspeed = math.abs(tempXspeed)
Yspeed = math.abs(tempYspeed)
Zspeed = math.abs(tempZspeed)
XZdirection = tempXZdirection
end
XZspeed = math.sqrt(Xspeed*Xspeed + Zspeed*Zspeed)
health = memory.readbyte(0x00010041)
inlvlCarrots = memory.readbyte(0x00069525)
inlvlGoldenCarrots = memory.readbyte(0x00069574)
inlvlClocks = memory.readbyte(0x00069514)
inlvlACME = memory.readbyte(0x00010044)
totalCarrots = memory.readbyte(0x00010043)
totalGoldenCarrots = (memory.readbyte(0x0001013C)*256) + memory.readbyte(0x00010047) --addr 0x0001013C is a roll-over counter for addr 0x00010047
totalClocks = memory.readbyte(0x00010045)
abilities = memory.readbyte(0x00010048) --0x08 == SuperJump
if abilities >= 0x08 then
jump = true
abilities = abilities - 0x08
end
-- TODO: Get the flags for the rest of the abilities
gui.opacity(1.0)
gui.text(0,0,string.format("Pos (%6d,%6d,%6d)\n",Xpos,Ypos,Zpos)
..string.format("Speed XZ: %3d Angle: %3d\n",XZspeed,XZdirection)
..string.format("Speed Y: %3d\n\n",Yspeed)
..string.format("Health: %d\n",health)
..string.format("Carrots: %d\n",totalCarrots)
..string.format("LVL Golden: %2d Total Golden: %3d\n",inlvlGoldenCarrots,totalGoldenCarrots)
..string.format("LVL Clocks: %2d Total Clocks: %3d\n",inlvlClocks,totalClocks)
..string.format("ACME boxes: %d\n\n",inlvlACME)
..string.format("Jump: %s\n",tostring(jump))
..string.format("Music: %s\n",tostring(music))
..string.format("Sesame: %s\n",tostring(sesame))
..string.format("Fan: %s\n",tostring(fan)))
XposOld = Xpos
YposOld = Ypos
ZposOld = Zpos
end
gui.register(hud)