I'm trying to implement this in Physica, my Scratch-based physics engine. I tried adding it and the ball glitched out (couldn't move on the x axis at all). Does anyone know how to do this?
Asked
Active
Viewed 185 times
0
-
You're never assigning anything to Xv, and in the "Touch" function you're never doing anything with the X-axis. I don't think this is a glitch as much as missing functionality. – DCCoder May 15 '21 at 00:26
2 Answers
0
If it's a physics engine, then every object should have added variables for speed, and then you manipulate the speed:
To change the speed:
When ... (whenever your drag release is)
set Vx to 10
this example has a drag function: https://en.scratch-wiki.info/wiki/Draggable_Sprite_Feature
In the physics engine, speed constantly moves your object:
When green flag
forever
add Vx to x
add Vy to y

boisvert
- 3,679
- 2
- 27
- 53
-
-
Example of drag on scratch wiki: https://en.scratch-wiki.info/wiki/Draggable_Sprite_Feature – boisvert May 22 '21 at 15:04
0
@boisvert pretty much answered your question. But if you want to sense drag releasing, use this code:
when green flag
set drag mode to draggable
forever
wait until touching mouse pointer and mouse down
wait until not mouse down
point toward mouse pointer
set V to distance to mouse pointer * 2
along with this:
when green flag
forever
set V to V*0.9
move V steps
if on edge, bounce
It's not the most perfect code, but it will work

CoderTang
- 460
- 5
- 14