Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Joint axes
- blender67
- Scratcher
10 posts
Joint axes
How can I make a human-like leg using three sprites (the thigh, knee (or just a joint), and shin). It does not drop limp when not being dragged around, and it's length does not vary depending on the mouse's position
- Birdlegs
- Scratcher
1000+ posts
Joint axes
To make a rotating joint, it can generally work to place the costume center where the joint should be and then use the Go To block. But if you want multiple joints, an easy, non-trig way would be to have the jointed sprite go to the object, save its direction in a variable, point in the direction of what it's jointed to, rotate any necessary degrees, and finally step forward to the point it needs to join with. Then it should return to the orientation the variable saved. This might lag with lots of joints, so if you know trig, that's best, I think. Also, you might wanna run all that in non-refresh if it gets wonky.
Last edited by Birdlegs (May 28, 2015 01:42:15)
Get a sweet lick of my new game right here! It's a tasty one!
- -Scratcher-
- Scratcher
100+ posts
Joint axes
Or trigonometrical
Attach Sprite2 to Sprite1:
Attach Sprite2 to Sprite1:
when green flag clicked
set [distance v] to [50] //distance from Sprite1's midpoint
set [angle v] to [0] //shifted angle from Sprite1
forever
set x to (([x position v] of [Sprite1 v]) + ((distance) * ([sin v] of (([direction v] of [Sprite1 v]) + (angle)))))
set y to (([y position v] of [Sprite1 v]) + ((distance) * ([cos v] of (([direction v] of [Sprite1 v]) + (angle)))))
end
Last edited by -Scratcher- (May 28, 2015 11:47:39)
- blender67
- Scratcher
10 posts
Joint axes
Or trigonometrical
Attach Sprite2 to Sprite1:when green flag clicked
set [distance v] to [50] //distance from Sprite1's midpoint
set [angle v] to [0] //shifted angle from Sprite1
forever
set x to (([x position v] of [Sprite1 v]) + ((distance) * ([sin v] of (([direction v] of [Sprite1 v]) + (angle)))))
set y to (([y position v] of [Sprite1 v]) + ((distance) * ([cos v] of (([direction v] of [Sprite1 v]) + (angle)))))
end
Thanks
- -Scratcher-
- Scratcher
100+ posts
Joint axes
You just have to set the midpoint for each body part, which is usually the joint with the “parented” body part. The easiest and safest way is to use the triginomical scripts, you just have to play around a bit with the values. And how would the right leg vary?
If you need help, I once made a project about this, just click see inside to see how I did it https://scratch.mit.edu/projects/1138616/
- blender67
- Scratcher
10 posts
Joint axes
That doesn't help very much though.You just have to set the midpoint for each body part, which is usually the joint with the “parented” body part. The easiest and safest way is to use the triginomical scripts, you just have to play around a bit with the values. And how would the right leg vary?
If you need help, I once made a project about this, just click see inside to see how I did it https://scratch.mit.edu/projects/1138616/
What values can I change specifically?
- -Scratcher-
- Scratcher
100+ posts
Joint axes
Just use the script I postet above ↑. You can change the values of the variables “distance” and “angle” before starting the project, they stay constant while the project is running though.That doesn't help very much though.You just have to set the midpoint for each body part, which is usually the joint with the “parented” body part. The easiest and safest way is to use the triginomical scripts, you just have to play around a bit with the values. And how would the right leg vary?
If you need help, I once made a project about this, just click see inside to see how I did it https://scratch.mit.edu/projects/1138616/
What values can I change specifically?
Just follow these instructions:
- Add two new Sprites: Sprite1, Sprite2.
- For each Sprite1 and Sprite2, draw a long, narrow rectangle as a costume and center them in the middle of the shortest edge.
- For Sprite2, add the exact script I postet already. Before, you have to create these two variables. When you're done with it, make them show on the screen by clicking the checkbox of each variable under the data tab.
- Move the variables on the screen, double click until they change to the slider and set the slider min and max (right-click) for each: For the distance variable from 0 to 200; for the angle variable from 0 to 360.
- Now click the green flag and change these values while rotating Sprite1, you will see what these two values are going to do and then you will understand for your project
Last edited by -Scratcher- (May 30, 2015 22:22:50)
- -Scratcher-
- Scratcher
100+ posts
Joint axes
You're welcome! If you have more questions or there is something going wrong, just let me know. Thank you so much!
- WizardQuest
- Scratcher
16 posts
Joint axes
im curious what do u mean by save its direction as a variable?
- deck26
- Scratcher
1000+ posts
Joint axes
Create a variable, save the direction in that variable. im curious what do u mean by save its direction as a variable?
- WizardQuest
- Scratcher
16 posts
Joint axes
Can you tell me how to do that? I'm kind of a newbie at this. I've been on scratch offline for about a year.
- abcde1234qwe
- Scratcher
500+ posts
Joint axes
Please don't necropost. (Necroposting means you post on an old topic). help me
If you would want help, please create a new topic and explain what you need help with,
View my new project please.
–> Learn About Scratch Blocks! <–
500+ posts let's go.
Helper in the Help with Scripts topic.
- Discussion Forums
- » Help with Scripts
- » Joint axes