Discuss Scratch

theYOLOcactus
Scratcher
33 posts

something is off...

I am working on a sequel of my game and am trying to make an attack that curves and hits from the side. I made a testing project but the starting position of the arrow is offset so please check it out, remix and clarify what happened, and how you fixed it..

<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#000000><_::#ffff00><_::#000000><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#000000><_::#ffff00><_::#ffff00><_::#ffff00><_::#000000>::#f0f0f0
<_::#ffff00><_::#000000><_::#000000><_::#000000><_::#ffff00>::#f0f0f0
Hello there. I exist.
theYOLOcactus
Scratcher
33 posts

something is off...

that is great and all, but if you studied the scripts in the project I linked, you would have found that I tried to give it a target.

<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#000000><_::#ffff00><_::#000000><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#000000><_::#ffff00><_::#ffff00><_::#ffff00><_::#000000>::#f0f0f0
<_::#ffff00><_::#000000><_::#000000><_::#000000><_::#ffff00>::#f0f0f0
Hello there. I exist.
footsocktoe
Scratcher
1000+ posts

something is off...

theYOLOcactus wrote:

I am working on a sequel of my game and am trying to make an attack that curves and hits from the side. I made a testing project but the starting position of the arrow is offset so please check it out, remix and clarify what happened, and how you fixed it..

Why does it go to sprite 2 to create clone of myself and then point towards sprite 1? Isn't that backwards?


SHOOT THE SPACE MONSTERS! ….. A game everyone can play! Bright colors, bonky sounds!
THE 12 BALLS OF CRAZY AL ……. New scrolling adventure game!

theYOLOcactus
Scratcher
33 posts

something is off...

sprite2 is the attacker
sprite1 is the target

<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#000000><_::#ffff00><_::#000000><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#000000><_::#ffff00><_::#ffff00><_::#ffff00><_::#000000>::#f0f0f0
<_::#ffff00><_::#000000><_::#000000><_::#000000><_::#ffff00>::#f0f0f0
Hello there. I exist.
footsocktoe
Scratcher
1000+ posts

something is off...

Let me ask you this… Is what you are trying to do is have an arrow go from one sprite to the other sprite, but in a curving path?


SHOOT THE SPACE MONSTERS! ….. A game everyone can play! Bright colors, bonky sounds!
THE 12 BALLS OF CRAZY AL ……. New scrolling adventure game!

theYOLOcactus
Scratcher
33 posts

something is off...

yes

<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#000000><_::#ffff00><_::#000000><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#000000><_::#ffff00><_::#ffff00><_::#ffff00><_::#000000>::#f0f0f0
<_::#ffff00><_::#000000><_::#000000><_::#000000><_::#ffff00>::#f0f0f0
Hello there. I exist.
gtoal
Scratcher
1000+ posts

something is off...

remix: https://scratch.mit.edu/projects/170738349/

I deleted your code and used deck26's “gradual turn to” algorithm instead.

Last edited by gtoal (Aug. 8, 2017 05:37:41)

theYOLOcactus
Scratcher
33 posts

something is off...

Thank you so much! I will definitely use it in my project.

<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#000000><_::#ffff00><_::#000000><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#000000><_::#ffff00><_::#ffff00><_::#ffff00><_::#000000>::#f0f0f0
<_::#ffff00><_::#000000><_::#000000><_::#000000><_::#ffff00>::#f0f0f0
Hello there. I exist.
theYOLOcactus
Scratcher
33 posts

something is off...

gtoal wrote:

remix: https://scratch.mit.edu/projects/170738349/

I deleted your code and used deck26's “gradual turn to” algorithm instead.

I tried to put it in my game's code but some stuff just goes in circles…

(Edit: I tried tinkering, it did not work…)

Last edited by theYOLOcactus (Aug. 8, 2017 19:03:12)


<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#000000><_::#ffff00><_::#000000><_::#ffff00>::#f0f0f0
<_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00><_::#ffff00>::#f0f0f0
<_::#000000><_::#ffff00><_::#ffff00><_::#ffff00><_::#000000>::#f0f0f0
<_::#ffff00><_::#000000><_::#000000><_::#000000><_::#ffff00>::#f0f0f0
Hello there. I exist.
gtoal
Scratcher
1000+ posts

something is off...

theYOLOcactus wrote:

gtoal wrote:

remix: https://scratch.mit.edu/projects/170738349/

I deleted your code and used deck26's “gradual turn to” algorithm instead.

I tried to put it in my game's code but some stuff just goes in circles…

(Edit: I tried tinkering, it did not work…)

With that algorithm I suspect that if source and target are in just the wrong relationship it may be possible to go into ‘orbit’ around a target as you keep turning and turning towards it.

I have a couple of slightly more refined versions of the algorithm that solve that problem, but the code is more complex. Have a look for a bunch of projects called “Curvinator”. It's basically the same algorithm in a slightly different context (drawing the curve rather than following it in real time) so you should be able to adapt it.

If you share the game with the code added I'll look at it when I get a chance.

G
gtoal
Scratcher
1000+ posts

something is off...

I almost forgot. An alternative algorithm. Take the distance from sprite 1 to sprite 2, and halve it. Place a point off to one side at 90 degrees from the line between the sprites at the halfway point, maybe 25% of the distance off to one side.

Then find the circle that goes through the 3 points and follow that. Fortunately code to fit a circle to three points is easy to find on Scratch, eg https://scratch.mit.edu/projects/14778064/

with this algorithm your curves will be smooth, symmetrical, and deterministic.

Powered by DjangoBB