Hello all
i have this simple source code but im keep getting :
ERROR:SCRIPT: main/hero.script:30: bad argument #2 to β__addβ (vector3 expected, got number)
stack traceback:
[C] in function __add
main/hero.script:30: in function <main/hero.script:28>
The source code , i think i done every thing right , looks like the fixed_update(self,dt) β position + self.velocity * dt
is not vector although i did set it to vector in init
local DIRECTION_RIGHT=5
local DIRECTION_LEFT=-5
local BASE_VELOCITY = 500
function init(self)
msg.post("#","acquire_input_focus")
self.velocity = vmath.vector3(0,0,0)
end
function walk(self)
self.velocity = BASE_VELOCITY * self.direction
end
function flip(direction)
sprite.set_hflip("#sprite",direction < 0)
end
function animate(action)
if action.pressed then
sprite.play_flipbook("#sprite","run")
elseif action.released then
sprite.play_flipbook("#sprite","idle")
end
end
function fixed_update(self,dt)
local position = go.get_position();
position = position + self.velocity * dt
go.set_position(position)
end
function on_input(self, action_id, action)
animate(action)
self.direction = (action_id == hash("right")) and DIRECTION_RIGHT or DIRECTION_LEFT
walk(self)
flip(self.direction)
end
Thanks