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:
when gf clicked set [turn speed v] to [0] forever if <key [left arrow v] pressed?> change [turn speed v] by (-1) end if <key [right arrow v] pressed?> change [turn speed v] by (1) end set [turn speed v] to ((turn speed) * (0.9)) endNow, you'll want to make a script that turns the sprite using this (turn speed) variable.
when gf clicked forever set [angle v] to ((((direction) + (45)) mod (90)) - (45) ) endThis 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.
when gf clicked forever turn right (turn speed) degrees set y to ((-100) + ( ( (([sqrt v] of (2)) - (1)) * (25)) * (([abs v] of (angle)) / (45)) ) ) endThe turning is kind of obvious.
when gf clicked forever if <<not <key [left arrow v] pressed?>> and <not <key [right arrow v] pressed?>>> if <([abs v] of (angle)) > [3]> //"accelerate" to fall on its side if <(angle) > (0)> change [turn speed v] by ( ((45) - ([abs v] of (angle))) * (-0.03)) else change [turn speed v] by ( ((45) - ([abs v] of (angle))) * (0.03)) end else //almost on its side, realign it set [turn speed v] to [0] //stop turning point in direction ((round((direction)/(90)))*(90)) end end endI'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 works If you can't get it to work, I'll a working version of this project later.
Last edited by JSO (2012-08-26 15:07:38)
Offline