I have a character that I want to be able to “grab” an object so that it moves with him. I want to go into a “grab” mode when the object is touched and then exit the “grab” mode when the object is touched a second time. I’m having trouble figuring out how to do this. I know why my current code isn’t working right (it’s enabling the grab and then disabling before exiting the function), but I feel like I need some sort of a way to jump out of the if loops when one condition is satisfied… so only one thing (turning grab mode on or off) is being done per click.
[lua]function grabEnabled(event)
if event.phase == “began” then
if grabIsEnabled == false then
if crate.x - character.x <= 5 then
print(“grab enabled”)
grabIsEnabled = true
end
end
if grabIsEnabled == true then
grabIsEnabled = false
print(“grab disabled”)
end
end
return true
end[/lua]
The second question: Is there a better way to “link” the character and object together besides forcing the x-values? Is there some way to temporarily join the two objects through the physics engine? [import]uid: 146966 topic_id: 34909 reply_id: 334909[/import]