Distance between objects doesn't seem to work correctly

It appears to take the initial position values but never update with new positions of moving objects. Example, I have a character moving using the set world velocity. The position used for the character in the distance calculation is the original position.

Hello William_Wallace,

could you please provide us source code of your example?

The “do” code was to have the character “jump” over an obstacle using up and down velocity changes. The “jump” works but the trigger in the “while” doesn’t. The values for the position of the “Moving man 1” don’t change. I tried several approaches to “manually” calculate the distance but none seemed to work. I used “Execute in Parallel” and that improved the manual approach some but still wasn’t sensitive to the actual position so the jump either occurs too early or too late. It almost appears that each instruction takes 1 second so by the time the jump is triggered the character has traveled many “meters”.

Background: I teach Physics and want to use the Blockly coding to challenge students to demonstrate motion and force concepts. The jump was a challenge for those who are already adept at basic coding. I have many questions and questions about the Physics engine and how the code relates to Physics parameters. I’m happy to consolidate them and send them in an email to save Forum interactions.

Hi,

Keep in mind that “repeat while” block behaves the same way as “while” loop in most programming languages. That means that if condition is false at the moment when your program flow encounters the while loop, then this while loop is simply skipped and next statement is executed. Even if condition becomes true later in time, body of while loop won’t be executed anyway.

Use “on update” block from “events” section in combination with “if” block to achieve what you expect, like this:

3 Likes