This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-06-28 11:21:40

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

i need some trig help...

okay. so i'm making this game, where you are a cube, and you get to the goal by turning the level. i need the character to stay in the position he would be in as if he was taped to the level. help!!!


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#2 2011-06-28 11:38:57

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: i need some trig help...

Okay, I think this script should work (I don't have any way to test it right now though so I'm not sure):

Code:

When green flag clicked
forever
    if <key left arrow pressed> or <key right arrow pressed>
        set [distance] to sqrt[ ((x position) * (x position)) + ((y position) * (y position)) ]
        go to x: (distance * cos (direction of level)) y: (distance * sin (direction of level))

The only problem is that you have to convert Scratch's angle units to their proper values. There's a formula to do that, but I don't quite remember what it is.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#3 2011-06-28 11:46:54

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

awsome! thanks. you only mixed up the sine and cosine. i think it's sine for x, and cosine for y. thats what i go by.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#4 2011-06-28 11:49:09

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

uh-oh. turns out it doesn't work. when i go to a side, it turns and stays on the wrong one.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#5 2011-06-28 11:49:12

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: i need some trig help...

chipguy wrote:

awsome! thanks. you only mixed up the sine and cosine. i think it's sine for x, and cosine for y. thats what i go by.

Nope. Cosine is x, sine is y.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#6 2011-06-28 11:50:10

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

really? because when i did that, the scene turned one way, and the guy went the other.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#7 2011-06-28 19:55:34

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

bumpa bumpa!


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#8 2011-06-28 20:57:10

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: i need some trig help...

chipguy wrote:

really? because when i did that, the scene turned one way, and the guy went the other.

You're probably using Scratch direction and not math direction (what Harakou is referring to).  I think the conversion is "((direction-90)*-1)".

Last edited by Kileymeister (2011-06-28 20:57:45)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#9 2011-06-28 22:22:25

redturtle3
Scratcher
Registered: 2010-08-07
Posts: 6

Re: i need some trig help...

The trigg function depends on the angle you're using
A
x  x
x    x
B x  x C
in the triangle above
If you have angle C and the side opposite of B
x= side b/cosC
y= side b/ sinC

If you have angle A and the side opposite of B
x= side a/sinC
y= side a/cosC

This help?

Offline

 

#10 2011-06-29 05:49:41

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: i need some trig help...

Scratch measures "direction" with zero defined as straight up, where physics and math books use to the right (the positive x-axis) as the "zero direction".

To use sine and cosine in Scratch;  If calculating x and y components of a velocity, Vx, Vy and Vmag are related like this:

Vx = Vmag * Sin (direction)

Vy = Vmag * Cos (direction)

Offline

 

#11 2011-06-29 07:55:38

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

Kileymeister wrote:

chipguy wrote:

really? because when i did that, the scene turned one way, and the guy went the other.

You're probably using Scratch direction and not math direction (what Harakou is referring to).  I think the conversion is "((direction-90)*-1)".

still, not working...  sad


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#12 2011-06-29 08:02:32

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

i have an idea that uses no math whatsoever, butit's probably very, err, not smooth.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#13 2011-06-29 10:05:07

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: i need some trig help...

chipguy wrote:

Kileymeister wrote:

chipguy wrote:

really? because when i did that, the scene turned one way, and the guy went the other.

You're probably using Scratch direction and not math direction (what Harakou is referring to).  I think the conversion is "((direction-90)*-1)".

still, not working...  sad

Hm... what exactly is it doing the doesn't work right?


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#14 2011-06-29 10:27:37

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

Harakou wrote:

chipguy wrote:

Kileymeister wrote:


You're probably using Scratch direction and not math direction (what Harakou is referring to).  I think the conversion is "((direction-90)*-1)".

still, not working...  sad

Hm... what exactly is it doing the doesn't work right?

okay, first, when you go to one side and turn it, it teleports to a different side, and then turns. if you turn on that side that it teleported to, it works fine. second, the view is ver shaky, and that you kind of see 2 veiws of the character, and it ends up showing at either one...


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#15 2011-06-29 11:48:00

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

Bumpnumpbumpanumpawumpa


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#16 2011-06-29 12:27:16

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

*


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#17 2011-06-29 15:27:48

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: i need some trig help...

chipguy wrote:

*

Instead of just bumping your question, why not post a project.  I don't think anyone can help based on "still, not working...".

Offline

 

#18 2011-06-29 15:33:41

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

yeah, you're right.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#19 2011-06-29 15:35:34

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

chipguy wrote:

yeah, you're right.

done! it's my latest project.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#20 2011-06-29 15:36:38

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: i need some trig help...

I didn't look into the details of the math posts above, but I did notice the triangle diagram with the X's. You said:

A
x  x
x    x
B x  x C

And then explained the math formulae for it. That's correct, but doesn't help much in Scratch.
The directions on Scratch work like this instead:

.      C
    x  x
  x    x
A x x B

Where A is the direction, C is the Y value and B is the X (well, kind of, but you get what I mean - I hope). Then Cos is for X and Sin is for Y.

Offline

 

#21 2011-06-29 15:48:50

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

okay... did you see the project? the guy turns the right way, but now, the guy teleports to a side and goes with that.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#22 2011-07-05 23:51:28

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: i need some trig help...

Hi again; I see your project is still having the same problem as before. I'm really sorry for taking so long to get back to you on this; I was without internet for a while. I honestly am getting the same problem. I'm getting closer, but Scratch's infuriating trig system is really giving me problems. Should I post what I have so far?


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#23 2011-07-06 08:17:40

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

Harakou wrote:

Hi again; I see your project is still having the same problem as before. I'm really sorry for taking so long to get back to you on this; I was without internet for a while. I honestly am getting the same problem. I'm getting closer, but Scratch's infuriating trig system is really giving me problems. Should I post what I have so far?

are you sure i'm having problems? so far, thanks to kileymeister, i think it works...


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#24 2011-07-06 10:30:21

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: i need some trig help...

chipguy wrote:

Harakou wrote:

Hi again; I see your project is still having the same problem as before. I'm really sorry for taking so long to get back to you on this; I was without internet for a while. I honestly am getting the same problem. I'm getting closer, but Scratch's infuriating trig system is really giving me problems. Should I post what I have so far?

are you sure i'm having problems? so far, thanks to kileymeister, i think it works...

Oh, it does? I thought in your previous post you said it still wasn't working. Sorry.  hmm


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#25 2011-07-06 11:02:42

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: i need some trig help...

Harakou wrote:

chipguy wrote:

Harakou wrote:

Hi again; I see your project is still having the same problem as before. I'm really sorry for taking so long to get back to you on this; I was without internet for a while. I honestly am getting the same problem. I'm getting closer, but Scratch's infuriating trig system is really giving me problems. Should I post what I have so far?

are you sure i'm having problems? so far, thanks to kileymeister, i think it works...

Oh, it does? I thought in your previous post you said it still wasn't working. Sorry.  hmm

no problem!


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

Board footer