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!!!
Offline
Okay, I think this script should work (I don't have any way to test it right now though so I'm not sure):
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.
Offline
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)
Offline
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
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
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...
Offline
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...
![]()
Hm... what exactly is it doing the doesn't work right?
Offline
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...
![]()
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...
Offline
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
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?
Offline
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...
Offline
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.
Offline
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.
![]()
no problem!
Offline