00:00
00:00
Newgrounds Background Image Theme

Daveman4298 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: rotation on angles

1,686 Views | 6 Replies
New Topic Respond to this Topic

AS: rotation on angles 2006-07-26 14:41:21


AS: main, the almighty thread being used by n00bs. and im one of them

well, i was posting threads asking for a code like this, and frankly, i was to lazxy to do it myself. so i finally got enough motivation to get up (more like sit down) and do it my self.

alright, all this really does is have to invisble variables (y1, y2) that start at the top of the movie clip. the keep on going down and down and down, until they hit the ground, and rotate the movieclip to fill the space inbetween

and turns it into a function

mainly used for platformers, and i tested it by using AS: platformer by pyro111 since i was in a hurry.

like always, start out with the onclipevent handler;

onClipEvent (enterFrame) {
function rotateWithGround()
{
// the 'function' part turns it into a function

now time to add the y1 and y2 variables..

var y1 = 0; // starts it at the top of the screen
var y2 =0;

now to make them drop by the _x:

var x1 = _x;
var x2 = _x+ _width;

and now:

// get the left side of characters coords with the ground
while (_root.ground.hitTest(x1,y1,true)== false && y1 <10000){y1++;}
// get the right side of character's coords with the ground
while (_root.ground.hitTest(x2,y2,true)== false && y2 < 10000){y2++;}

then...

var ystep = y2-y1; var xstep = x2-x1;
var theta = Math.atan(ystep/xstep);// currently in radians
var degreeTheta = theta/(2* Math.PI) * 360; // now in degrees

_rotation = degreeTheta;

now this part is optional, but here it goes.

make a textbox, go to properties and make it dynamic text.

below the 'dynamic text' box, in the box blelow, type this in:

thetaText

and now, you have it.

making it a platformer, welll,

thnaks pyro for script

make the character, convert to symbol, give it the instance name "olayer" wihtout the quotes.

give it this script:

onClipEvent (load) {
jh = 15;
grav = 0;
speed = 10;
jumpHeight = 11;
scale = _xscale;
}
onClipEvent (enterFrame) {
function rotateWithGround()
{
var y1 = 0; // starts it at the top of the screen
var y2 =0;
var x1 = _x;
var x2 = _x+ _width;

// get the left side of mario's coords with the ground
while (_root.ground.hitTest(x1,y1,true)== false && y1 <10000){y1++;}
// get the right side of mario's coords with the ground
while (_root.ground.hitTest(x2,y2,true)== false && y2 < 10000){y2++;}

var ystep = y2-y1; var xstep = x2-x1;
var theta = Math.atan(ystep/xstep);// currently in radians
var degreeTheta = theta/(2* Math.PI) * 360; // now in degrees

_rotation = degreeTheta;

_root.thetaText.text = "ystep =" + ystep + " xstep=" + xstep;
_root.thetaText.text = "theta:" + theta + " y/x:" + ystep/xstep;
}

grav++;
_y += grav;
while (_root.ground.hitTest(_x, _y, true))
{
grav = 0;
_y--;
if(Key.isDown(jump))
{
grav = -jh;
}
}
/*
if(_root.curve.hitTest(this)){

_rotation += 40
}
*/
// attempting to rotate properly

if (Key.isDown(Key.RIGHT))
{
_x += speed;
_xscale = +scale;
this.gotoAndStop(2);

if (_root.ground.hitTest(_x, _y+3, true))
{
this.gotoAndStop(2);
}
else
{
this.gotoAndStop(1);
}
rotateWithGround();
}
else if (Key.isDown(Key.LEFT))
{
_x -= speed;
_xscale = -scale;

rotateWithGround();

if (_root.ground.hitTest(_x, _y+3, true))
{
this.gotoAndStop(2);
}
else
{
this.gotoAndStop(1);
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79)) {
this.gotoAndStop(1);
}
}
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(Key.SPACE)) {
this.gotoAndStop(4);
}
if (Key.isDown(Key.SPACE) && _root.ground.hitTest(_x, _y+3, true)) {
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(3);
}
if (_root.ground.hitTest(_x+(_width/2), _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2), _y-((_height/6)*4), true)) {
_x -= speed;
}
if (_root.ground.hitTest(_x-(_width/2), _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2), _y-((_height/6)*4), true)) {
_x += speed;
}
if (_root.ground.hitTest(_x, _y-_height, true)) {
grav = 2;
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
}

now draw the ground, (lines dont work) make it a moviclip, give it the instance name "ground without qoutes, press ctrl+enter, and there you have it...

thnaks pyro111 for the platformer script

Response to AS: rotation on angles 2006-07-26 14:42:28


Wow, looks complicated, can you post an example?

Lots of AS:s Today. Including Mine, yay:)

BBS Signature

Response to AS: rotation on angles 2006-07-26 14:43:01


I rather use this way.


BBS Signature

Response to AS: rotation on angles 2006-07-26 14:43:28


there, and heres a example of what is hould be like:

ta-da

arrow keys=movement

space is jump

Response to AS: rotation on angles 2006-07-26 14:46:26


At 7/26/06 02:43 PM, ViktorHesselbom wrote: I rather use this way.

ok, so ive made this whole script for nuttin...

oh well

Response to AS: rotation on angles 2006-07-26 14:49:53


At 7/26/06 02:46 PM, red-stapler wrote:
At 7/26/06 02:43 PM, ViktorHesselbom wrote: I rather use this way.
ok, so ive made this whole script for nuttin...

oh well

Nah, its a different script really. Only one thing though. It looks unrealistic when he jumps. He shouldn't curve when he jumps.

You can use a 'jump' variable, i'm just saying for all the newbies :)

BBS Signature

Response to AS: rotation on angles 2006-07-26 14:52:32


Nah, its a different script really. Only one thing though. It looks unrealistic when he jumps. He shouldn't curve when he jumps.

You can use a 'jump' variable, i'm just saying for all the newbies :)

k, i might update that later.

thnx for the reply