[C]: in function 'animate’
craft/craft.script:42: in function <craft/craft.script:31>
ERROR:SCRIPT: craft/craft.script:42: The property ‘position.y’ of ‘[main:/craft]’ has incorrect type
Jens,
Thanks but here is whole update. If I take out go.set_position§ it does not animate, if I change animate to p.y no animation.
function update(self, dt)
local p = go.get_position()
if self.elapsed_time ~= nil then
p.y = p.y + self.speed * dt * self.elapsed_time
end
if p.y < min_y then
p.y = min_y
elseif p.y > max_y then
p.y = max_y
end
go.set_position(p)
go.animate(go.get_id(),"position.y", go.PLAYBACK_ONCE_FORWARD, p, go.EASING_LINEAR, 2, 0)
self.speed = 0
end
Didn’t realize you had it in the update loop. That is probably a bad idea, you should probably send a message and trigger an animation instead.
Having the go.animate in an update loop will most likely make a new animation start each frame, which will terminate the old animation. And since you’ve set the duration to 2 seconds (120 frames) it wont even move a single pixel by the time it is reset.
Why are you both setting the position and doing go.animate() every frame?
It’s worth noting that if an animation is running and you try to animate the same property again before the first animation has finished nothing will happen. You need to do go.cancel_animation() before starting a new animation if you want to be absolutely sure the animation will play.
PS Use the shortcut “.” instead of go.get_id() to reference the game object itself:
Well, I mean, you would typically do one of these, but most likely never both at the same time:
receive input in the on_input() function and then modify some variable (eg speed in direction corresponding to the received input) and manually move the game object in the update function (don’t forget to use dt!)
or
receive input in the on_input() function and start an animation (eg animation to the touch/click point) and let the system move the game object.