Incorrect type of property?(SOLVED)

I get this error

[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

in my update

go.set_position§
go.animate(go.get_id(),“position.y”, go.PLAYBACK_ONCE_FORWARD, p, go.EASING_LINEAR, 2, 0)

Replace: go.animate(go.get_id(),“position.y”, go.PLAYBACK_ONCE_FORWARD, p, go.EASING_LINEAR, 2, 0)
With: go.animate(go.get_id(),“position.y”, go.PLAYBACK_ONCE_FORWARD, p.y, go.EASING_LINEAR, 2, 0)

If you’re animating the property y on position you need to pass a number as argument.

You should remove go.set_position or it wont animate at all.

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.

What are you trying to do?

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:

go.animate(".", "position.y" ....)
1 Like

Because I don’t exactly know what I am doing. :slight_smile:

In essence its a modification of the parallax sidescroller tutorial.

A Plane character utilizing touch input.
It’s messy, kinda works though.

How should I do it differently?

Here is a video of game in action.
Game in action

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.
1 Like

Thanks @britzl I redid the code as #1 and it did the trick. Still moves same and no error.

on_update
go.set_position(p + dt * self.speed)

on_input
–down
self.speed = vmath.vector3(0, self.elapsed_time * -max_speed, 0)
–up
self.speed = vmath.vector3(0, self.elapsed_time * max_speed, 0)

1 Like