Discuss Scratch
- Koamodo975
-
Scratcher
1000+ posts
Smooth sword swinging?
Just started working on a game (top down hack-and-slash featuring Scratch Cat) from a while ago when I realized that the sword movement looks like a five-year-old made it (no offense to the five-year-olds). Currently, the sword is a separate sprite that sort of floats around Scratch; my code rn is
if for some reason TL;DR How do I add smoother tracking to the sword sprite, while also accounting fo the slashing that I'm gonna add?
when green flag clickedScratch's sword doesn't move as smoothly as I'd like with this code tho, I'm trying to get drag on the sword(aka the blade lags behind the mouse, and takes a second to catch up). This code's probably gonna cause problems with slashing aswell.
forever
point towards [mouse pointer v]
move (30) steps
if <(direction) < [0]> then
switch costume to [Sword2 v] //upside-down sword so that Scratch doesn't pinwheel when swinging
else
switch costume to [Sword1 v] //right-side-up sword
end
end
if for some reason TL;DR How do I add smoother tracking to the sword sprite, while also accounting fo the slashing that I'm gonna add?
Last edited by Koamodo975 (Aug. 12, 2024 19:23:15)
- bombardingppl
-
Scratcher
500+ posts
Smooth sword swinging?
when green flag clickedhopefully this is what you want
forever
go to x: () y: () //wherever, your sprite, etc.
if <slash not in play> then
set [angle difference v] to (((((angle1) - (angle2)) + (180)) mod (360)) - (180))
turn cw ((angle difference) / (8)) degrees //you can change the number to how fast you want the sword to catch up, less is faster, and more is slower.
move (30) steps
end
end
I forgot to mention, your angle variables should be your sword direction and sprite direction
also, the sword will never truly face towards the mouse, etc. and will be more like 0.000000001 degrees off. I don't know if that will cause problems, but just saying. And you can also stop it from going too low like 3.51*10^-20, because that's ridiculous. In the turn code, change it like this:
turn cw (<(angle difference)> [0.00001]> * ((angle difference) / (8))) degrees
Last edited by bombardingppl (Aug. 12, 2024 21:06:42)
- SpyCoderX
-
Scratcher
1000+ posts
Smooth sword swinging?
First part might work, but second part will break it because -20 is less than 0.00001. Just put a “abs of (angle difference)” in that check.when green flag clickedhopefully this is what you want
forever
go to x: () y: () //wherever, your sprite, etc.
if <slash not in play> then
set [angle difference v] to (((((angle1) - (angle2)) + (180)) mod (360)) - (180))
turn cw ((angle difference) / (8)) degrees //you can change the number to how fast you want the sword to catch up, less is faster, and more is slower.
move (30) steps
end
end
I forgot to mention, your angle variables should be your sword direction and sprite direction
also, the sword will never truly face towards the mouse, etc. and will be more like 0.000000001 degrees off. I don't know if that will cause problems, but just saying. And you can also stop it from going too low like 3.51*10^-20, because that's ridiculous. In the turn code, change it like this:turn cw (<(angle difference)> [0.00001]> * ((angle difference) / (8))) degrees
Last edited by SpyCoderX (Aug. 13, 2024 03:06:50)
- Koamodo975
-
Scratcher
1000+ posts
Smooth sword swinging?
Tried it, but the sword keeps jittering; it also seems to speed up the closer it gets to the mouse, instead of the opposite.when green flag clickedhopefully this is what you want
forever
go to x: () y: () //wherever, your sprite, etc.
if <slash not in play> then
set [angle difference v] to (((((angle1) - (angle2)) + (180)) mod (360)) - (180))
turn cw ((angle difference) / (8)) degrees //you can change the number to how fast you want the sword to catch up, less is faster, and more is slower.
move (30) steps
end
end
I forgot to mention, your angle variables should be your sword direction and sprite direction
also, the sword will never truly face towards the mouse, etc. and will be more like 0.000000001 degrees off. I don't know if that will cause problems, but just saying. And you can also stop it from going too low like 3.51*10^-20, because that's ridiculous. In the turn code, change it like this:turn cw (<(angle difference)> [0.00001]> * ((angle difference) / (8))) degrees
Link if ya need it: clikc
Last edited by Koamodo975 (Aug. 13, 2024 17:54:41)
- Koamodo975
-
Scratcher
1000+ posts
Smooth sword swinging?
I FIXED IT all I had to do is make the cursor point AWAY from the character and change the code slightly so that it was
turn cw ((angle difference) / (-10)) degreesinstead thank you both
Last edited by Koamodo975 (Aug. 13, 2024 19:43:59)
- bombardingppl
-
Scratcher
500+ posts
Smooth sword swinging?
your welcome!! Probably made a mistake in the post and not the test project… feel bad I made you troubleshoot haha
- Koamodo975
-
Scratcher
1000+ posts
Smooth sword swinging?
it's fine lol
aight I updated it a bit for more of a realistic effect, with the ‘arm’ positioned so that it's resting on your ‘shoulder’. goes in a wide arc when you swing, and then stays at the bottom until you swing again. just wondering if you know how to make sure the sword goes in the right direction so Scratch doesn't swing behind himself, and a workaround for the slashing to avoid the annoying costume flickering
aight I updated it a bit for more of a realistic effect, with the ‘arm’ positioned so that it's resting on your ‘shoulder’. goes in a wide arc when you swing, and then stays at the bottom until you swing again. just wondering if you know how to make sure the sword goes in the right direction so Scratch doesn't swing behind himself, and a workaround for the slashing to avoid the annoying costume flickering
Last edited by Koamodo975 (Aug. 14, 2024 16:46:52)
- Koamodo975
-
Scratcher
1000+ posts
Smooth sword swinging?
Oh, yeah. Sorry but I was discussing with an ‘associate’ of sorts on the project comments, so I forgot to update here.bumpIs there still an issue?
- Koamodo975
-
Scratcher
1000+ posts
Smooth sword swinging?
forgor about this tbh
Currently, Scratch has a smooth sword movement, but I want him to swing the sword in a more specific way. Instead of just swiping back and forth, I'm trying to get it to swing from one side of his body to the other, rotating around the ‘wrist’ as well as the ‘shoulder’ of Scratch, but rn it looks like he's tryna dig a hole with a sword
Currently, Scratch has a smooth sword movement, but I want him to swing the sword in a more specific way. Instead of just swiping back and forth, I'm trying to get it to swing from one side of his body to the other, rotating around the ‘wrist’ as well as the ‘shoulder’ of Scratch, but rn it looks like he's tryna dig a hole with a sword
Last edited by Koamodo975 (Sept. 11, 2024 17:51:44)
- SpyCoderTest
-
Scratcher
57 posts
Smooth sword swinging?
How's this?
https://scratch.mit.edu/projects/1066418582/
https://scratch.mit.edu/projects/1066418582/
- FlinchlyDropkick1
-
Scratcher
10 posts
Smooth sword swinging?
https://scratch.mit.edu/projects/1129243358/ here is my RPG game which I just started and I managed to make very cool sword swinging by fixing your project so that you can now swing under-arm
- Nolswit
-
Scratcher
100+ posts
Smooth sword swinging?
it's been 5 months. I'm sure he figured it out. also, please don't necropost (necroposting is when you post on a thread that is over a month old and is inactive) thank you
- Koamodo975
-
Scratcher
1000+ posts
Smooth sword swinging?
it's been 5 months. I'm sure he figured it out. also, please don't necropost (necroposting is when you post on a thread that is over a month old and is inactive) thank youactually I didn't but no necroposting still
- FlinchlyDropkick1
-
Scratcher
10 posts
Smooth sword swinging?
Sorry but i didn't know what Necroposting is cuz I didn't check the date. also what so bad about it
- Nolswit
-
Scratcher
100+ posts
Smooth sword swinging?
It just looked poorly upon, and we ask that people just make a new thread to make everything easier. also, it makes it hard to tell what your specific issue is because we see the original messages first before yours
- Koamodo975
-
Scratcher
1000+ posts
Smooth sword swinging?
Sorry but i didn't know what Necroposting is cuz I didn't check the date. also what so bad about itit brings up old posts and clutters the forums.
- Nolswit
-
Scratcher
100+ posts
Smooth sword swinging?
I apologize for my assumptionit's been 5 months. I'm sure he figured it out. also, please don't necropost (necroposting is when you post on a thread that is over a month old and is inactive) thank youactually I didn't but no necroposting still