I have this script in hero:
local gravity = -20
local jump_takeoff_speed = 900
local play_animation, update_animation
function init(self)
msg.post(".","acquire_input_focus")
self.position = go.get_position()
self.velocity = vmath.vector3(0,0, 0)
self.ground_contact = false
end
function final(self)
msg.post(".", "release_input_focus")
end
function update(self, dt)
local gravity = vmath.vector3(0, gravity, 0)
if not self.ground_contact then
self.velocity = self.velocity + gravity
end
go.set_position(go.get_position() + self.velocity *dt)
update_animation(self)
self.correction = vmath.vector3()
self.ground_contact = false
end
local function handle_geometry_contact(self,normal,distance)
local proj = vmath.dot(self.correction, normal)
local comp = (distance - proj)*normal
self.correction = self.correction + comp
go.set_position(go.get_position() + comp)
if normal.y > 0.7 then
self.ground_contact = true
end
proj = vmath.dot(self.velocity, normal)
if proj < 0 then
self.velocity = self.velocity - proj * normal
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
if message.group == hash("geometry") then
handle_geometry_contact(self, message.normal, message.distance)
end
end
end
local function jump(self)
if self.ground_contact then
self.velocity.y = jump_takeoff_speed
end
end
local function abort_jump(self)
if self.velocity.y > 0 then
self.velocity.y = self.velocity.y * 0.5
end
end
local function play_animation(self, anim)
-- only play animations which are not already playing
if self.anim ~= anim then
-- tell the spine model to play the animation
spine.play("#spinemodel", anim, go.PLAYBACK_LOOP_FORWARD, 0.15)
-- remember which animation is playing
self.anim = anim
end
end
local function update_animation(self)
-- make sure the right animation is playing
if self.ground_contact then
play_animation(self, hash("run_right"))
else
if self.velocity.y > 0 then
play_animation(self, hash("jump_right"))
else
play_animation(self, hash("fall_right"))
end
end
end
And i get this error :
stack traceback:
main/Assets/hero.script:31: in function <main/Assets/hero.script:21>
ERROR:SCRIPT: main/Assets/hero.script:31: attempt to call upvalue ‘update_animation’ (a nil value)
i just don’t get it why no clue. I was thinking maybe no spinemodel on hero but there is spine model, maybe no atlas attached but it is attached so help please