Like I asked, I want the player to be able to push the object, on contact.
My player.script:
function init(self)
msg.post(".","acquire_input_focus")
self.runSpeed = 50
self.curAnim = "idle"
msg.post("#idle", "play_animation", { id=hash("idle") })
self.speed = vmath.vector3()
end
function update(self, dt)
local pos = go.get_position()
if self.speed.x ~= 0 then
pos = pos + self.speed * dt
go.set_position(pos)
if self.curAnim ~= "run" then
msg.post("#idle", "play_animation", { id=hash("run") })
self.curAnim = "run"
end
end
end
function on_input(self, action_id, action)
if action_id == hash("RIGHT") then
if action.pressed then
self.speed.x = self.runSpeed
sprite.set_hflip("#idle", false)
elseif action.released then
self.speed.x=0
msg.post("#idle", "play_animation", { id=hash("idle") })
self.curAnim = "idle"
sprite.set_hflip("#idle", false)
end
end
if action_id == hash("LEFT") then
if action.pressed then
self.speed.x = self.runSpeed * -1
sprite.set_hflip("#idle", true)
elseif action.released then
self.speed.x=0
msg.post("#idle", "play_animation", { id=hash("idle") })
self.curAnim = "idle"
sprite.set_hflip("#idle", true)
end
end
end