1
\$\begingroup\$

I have a simple code which makes a sprite rotate and move,

extends Sprite

var vel = Vector2(1,1)

func _ready():
    print(position)
    pass

func _process(delta):
    rotation += PI * delta 
    position = position + vel * delta 
    pass

But in the line

position = position + vel * delta

when I multiply by delta, the sprite doesn't move, when I remove the delta, the sprite moves, why is that? I saw this tutorial and it seems to work fine.

\$\endgroup\$
5
  • \$\begingroup\$ How much is 1 unit? \$\endgroup\$
    – Bálint
    Feb 8, 2018 at 10:10
  • \$\begingroup\$ @Bálint 1 unit is 1 pixel \$\endgroup\$
    – azemda
    Feb 8, 2018 at 10:16
  • \$\begingroup\$ Hi, did you tried with set_process(true) in _ready? \$\endgroup\$
    – Tapirboy
    Feb 15, 2018 at 13:02
  • \$\begingroup\$ @Tapirboy Assuming I understand it correctly, no lifecycle methods in Godot 3.0 require manual enabling. This is only required if you're working with 2.1. \$\endgroup\$ Feb 18, 2018 at 0:19
  • \$\begingroup\$ @TARDISMaker Yes, true,sorry - my bad. So, another thing - can you really multiply a vector with a number (velocity * delta)? \$\endgroup\$
    – Tapirboy
    Mar 6, 2018 at 13:34

1 Answer 1

1
\$\begingroup\$

Since delta time is in seconds, that means the character'll move 1 pixels every second if Godot can even handle sub-pixel values. Try increasing the velocity

\$\endgroup\$
4
  • \$\begingroup\$ It moves when I increase the velocity, does it mean delta should be used for higher velocities but not required for lower velocities? \$\endgroup\$
    – azemda
    Feb 8, 2018 at 10:50
  • \$\begingroup\$ @azemda No, you should define the velocities in pixels/second instead of pixels/frame \$\endgroup\$
    – Bálint
    Feb 8, 2018 at 10:53
  • \$\begingroup\$ From Here, once multiplied by delta, it becomes pixels/seconds. \$\endgroup\$
    – azemda
    Feb 8, 2018 at 10:59
  • 2
    \$\begingroup\$ That's not correct, it becomes pixel per frsme once you multiply it. Measure it if you don't believe ne \$\endgroup\$
    – Bálint
    Feb 8, 2018 at 11:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .