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
For solution 1:
You want some sort of ‘grab’ mechanic, the player can grab and drop the object, and in so doing you will add or remove the player as the parent of the game object. Make sure when the player releases the object to assign the right new parent.
For solution 2:
Let the physics engine handle your collisions, and you can just edit the traits of the object and player.
For solution 3:
Make sure to read the whole page I linked, it goes through handling collisions with kinematic objects well, but to make sure that it handles well will require that you do implement what is described there.