Discuss Scratch
- Discussion Forums
- » Suggestions
- » a [point towards x( ) y( ) block
- willehren
-
21 posts
a [point towards x( ) y( ) block
I t would be nice if there was a block that made the sprite point towards an x and y “place”
- turkey3
-
1000+ posts
a [point towards x( ) y( ) block
You can use trigonometry to replicate this: so if I want to point toward x:40 y:60
Sorry if that's a bit off.
point in direction (([atan] of ((((60) - (y position)) / ((40) - (x position))))) - (90))
Last edited by turkey3 (June 14, 2013 21:39:15)
- kayybee
-
1000+ posts
a [point towards x( ) y( ) block
Wait, does that also work for the third and second quadrants? You can use trigonometry to replicate this: so if I want to point toward x:40 y:60Sorry if that's a bit off.point in direction (([atan] of ((((60) - (y position)) / ((40) - (x position))))) - (90))
- ProdigyZeta7
-
1000+ posts
a [point towards x( ) y( ) block
Here's the general script for it:
This code should work for all four quadrants. I can't go full nerd and explain the advanced properties trigonometry, but hopefully wikipedia can do that for you.
myX = x position
myY = y position
targetX = x position of target
targetY = y postion of target
if myY = targetY
{
if myX > targetX //if our Y positions are the same, I'll face either straight left or right
{
direction = -90
}
else
{
direction = 90
}
}
else
{
direction = atan((myX - targetX) / (myY - targetY))
if myY > targetY //because tangent can only yield up to 180 degrees, an extra 180 is added if the target's Y position is below yours
{
direction = direction + 180
}
}
- drmcw
-
1000+ posts
a [point towards x( ) y( ) block
Another method is to have a hidden sprite called target move that to the target destination then use point towards target.
- alexphan
-
1000+ posts
a [point towards x( ) y( ) block
I have two things to say.
1. What's the use for the block?
2.There are loopholes for it.
1. What's the use for the block?
2.There are loopholes for it.
- So_Awsome
-
10 posts
a [point towards x( ) y( ) block
I was working on a 3d model project, when I encountered a problem. I wanted my render sprite to point towards a specific point, but there wasn't a way of doing this without needing a lot of sprites (so that I could use the existing “point towards” block). So, I made a project with a new block, and I think you might want to see it. https://scratch-mit-edu.ezproxyberklee.flo.org/projects/65195004/ The new block serves this function, and I think it would be a good block addition.
- DaSpudLord
-
1000+ posts
a [point towards x( ) y( ) block
No support. Workaroundable. Look them up.
- So_Awsome
-
10 posts
a [point towards x( ) y( ) block
What do you mean? No support. Workaroundable. Look them up.
- DaSpudLord
-
1000+ posts
a [point towards x( ) y( ) block
I mean that it is possible to program it yourself.What do you mean? No support. Workaroundable. Look them up.
- So_Awsome
-
10 posts
a [point towards x( ) y( ) block
You're absolutely right, it is possible to program it yourself, but if you don't know trig, or you are new to scratch, it would be very hard.I mean that it is possible to program it yourself.What do you mean? No support. Workaroundable. Look them up.
- DaSpudLord
-
1000+ posts
a [point towards x( ) y( ) block
You can always move another sprite to that location and then point towards that sprite. That's what I used to do.You're absolutely right, it is possible to program it yourself, but if you don't know trig, or you are new to scratch, it would be very hard.I mean that it is possible to program it yourself.What do you mean? No support. Workaroundable. Look them up.
- So_Awsome
-
10 posts
a [point towards x( ) y( ) block
Yes, but for the project I was working on, more sprites would have slowed the program down. You can always move another sprite to that location and then point towards that sprite. That's what I used to do.
- DaSpudLord
-
1000+ posts
a [point towards x( ) y( ) block
Then use an existing sprite. Plus, most of the time, cloning can replace the need for having too many sprites.Yes, but for the project I was working on, more sprites would have slowed the program down. You can always move another sprite to that location and then point towards that sprite. That's what I used to do.
- So_Awsome
-
10 posts
a [point towards x( ) y( ) block
Here's the thing, you can't get a sprite to point toward its own clone. You can get it to point to other sprites' clones, but not its own. Then use an existing sprite. Plus, most of the time, cloning can replace the need for having too many sprites.
Last edited by So_Awsome (June 8, 2015 21:35:00)
- DaSpudLord
-
1000+ posts
a [point towards x( ) y( ) block
I know that. I'm saying that there are OTHER places in which you can use clones, like instead of repeatedly duplicating an enemy sprite to have multiple enemies at once, you can create clones of the original enemy sprite.Here's the thing, you can't get a sprite to point toward its own clone. You can get it to point to other sprites' clones, but not its own. Then use an existing sprite. Plus, most of the time, cloning can replace the need for having too many sprites.
- Doyousketch2
-
93 posts
a [point towards x( ) y( ) block
Whether or not it gets added to Scratch, I like the block you made.
I think it serves a purpose, and as far as I can tell, is well coded.
Yes, you can use another sprite, and point toward that.
I've done that before, especially at the center of the screen.
Tho, this seems like a more elegant method for drawing,
'cuz you wouldn't have to have your pen
constantly chasing around another sprite.
I think it serves a purpose, and as far as I can tell, is well coded.
Yes, you can use another sprite, and point toward that.
I've done that before, especially at the center of the screen.
Tho, this seems like a more elegant method for drawing,
'cuz you wouldn't have to have your pen
constantly chasing around another sprite.
- Alberknyis
-
1000+ posts
a [point towards x( ) y( ) block
No support, it's possible to program it yourself and you don't even need to know trigonometry; just find a project with it. If you can't find one I'll supply it to you.
- Discussion Forums
- » Suggestions
-
» a [point towards x( ) y( ) block