go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, 10, go.EASING_LINEAR, 1)
This line of code makes the gameobject move to a specific point which is 10 pixels. What If I want to move an object relative to its current position, meaning I want it to move by 10 pixels wherever its position is?
Something like this?
local obj = go.get_id()
local pos = go.get_position(obj)
go.animate(obj, "position.x", go.PLAYBACK_ONCE_FORWARD, pos.x + 10, go.EASING_LINEAR, 1)
I’ve already tried this but for some reason, it’s not working when I pass the values from another script.
Controller :
msg.post("object#script", "animate", {property="position.y", playback=go.PLAYBACK_LOOP_PINGPONG,
to=10, easing=go.EASING_LINEAR, duration=duration})
object:
local function animate( options )
local obj = go.get_id()
local pos = go.get_position( obj )
local y = pos.y
print("Y "..y)
go.animate(".", options.property, options.playback, y + options.to, options.easing, options.duration)
end
function on_message(self, message_id, message, sender)
if message_id == hash("animate") then
animate( message )
end
end
The code runs fine without the calculation of the current pos.
Also, this is a workaround, there should be a parameter “by” like the already existing “to”
Edit: Formatting isn’t working properly.
Do you get any errors?
Does it work if you let the controller just trigger the animation itself directly? Like;
local y_delta = 10
local p = go.get_position("object")
go.animate("object", "position.y", go.PLAYBACK_LOOP_PINGPONG, p.y + y_delta, go.EASING_LINEAR, duration)
2 Likes
Ok, it’s working fine now.
Thanks
2 Likes