i have a idea of a cube and when you press the left arrow key or right arrow key it rotates to move forward or backward and if it isnt flat against the ground it falls flat against the ground but i cant think of a script
Last edited by ZombieHappines (2012-08-25 16:44:54)
Offline
thats a lot to complicated
Offline
BirdByte wrote:
ZombieHappines wrote:
thats a lot to complicated
The script you are thinking of IS complicated. Lots of trigonometry is involved in the basics.
yes but there has to be one a little shorter
Offline
ZombieHappines wrote:
BirdByte wrote:
ZombieHappines wrote:
thats a lot to complicated
The script you are thinking of IS complicated. Lots of trigonometry is involved in the basics.
yes but there has to be one a little shorter
There is, though you wouldn't be able to controls the shape's radius, just the number of sides and their length.
Offline
i want a regular square that does that stuff without the side changing and the side length
sorry i meant square
Last edited by ZombieHappines (2012-08-25 23:02:29)
Offline
ZombieHappines wrote:
i want a regular cube that does that stuff without the side changing and the side length
Oh, you're thinking of a [b]cube[/cube] not a square. My mistake. Anyway that would require a lot of stamping or trigonometry.
Offline
Hey, I made a simpler script that hopefully does what you need. It's still not easy though - what you're trying to do is kind of complicated.
Start with creating a 50px by 50px square Since it's a bit of a hassle, I made one and uploaded it on Scratch Resources here
First of all, you want to be able to nicely control the *rotation* of the square with the arrow keys. For that we'll use something similar to the common velocity or speed method for scrollers. Instead of controlling the sprite's vertical/horizontal movement, we'll use it for rotation:
Now, you'll want to make a script that turns the sprite using this (turn speed) variable.whenclicked
setturn speed ▼to0foreverifkeyleft arrow ▼pressed?changeturn speed ▼by-1ifkeyright arrow ▼pressed?changeturn speed ▼by1setturn speed ▼toturn speed*0.9
This is the angle of the square, compared to it being flat on the ground (a number ranging from -45 to 0 to 45). It's also the amount of degrees we still have to turn before it's lying down on it's side.whenclicked
foreversetangle ▼to-moddirection+459045
The turning is kind of obvious.whenclicked
foreverturn
turn speeddegreesset y to-100+**-sqrt ▼of2125/abs ▼ofangle45
I'm still cleaning up my project I made to go with this tutorial before I share it, but you should really try to make your project from this tutorial - you'll hopefully understand how everything workswhenclicked
foreverifnotandkeyleft arrow ▼pressed?notkeyright arrow ▼pressed?if>abs ▼ofangle3"accelerate" to fall on its sideifangle>0changeturn speed ▼by*45-abs ▼ofangle-0.03elsechangeturn speed ▼by*45-abs ▼ofangle0.03elsealmost on its side, realign itsetturn speed ▼to0stop turningpoint in directionround*direction/9090
Last edited by JSO (2012-08-26 15:07:38)
Offline