ForumsProgramming ForumMaking a faked physics engine in As2?

39 15281
mightybob
offline
mightybob
363 posts
1,060

I want to make a faked physics engine in As2 like Sonic or Fancy Pants. So far all I got is gravity, when you hit the floor you stop going down, move left and right, and when you hit a steep enough slope you can't go up it.

But what I am currently trying to do is make it so the player can go through loops, or go up upside-down ramps, like this: [url=http://i39.tinypic.com/2uti2d4.jpg]

Any help would be appreciated!

  • 39 Replies
weirdlike
offline
weirdlike
1,309 posts
28,720

oops the forums don't allow greater or less than symbols and I don't feel like typing it again...

weirdlike
offline
weirdlike
1,309 posts
28,720

it kind of looks like your "while" statement is going into an infinite loop and freezing up, unlike the "if" statement which runs every "frame", the "while" statement runs independently

trace it

onEnterFrame = function()

{
//initially true every frame...
var whileBool:Boolean = true;

if(whileBool)
{
trace("If Active!"
//make it false, and it still traces
whileBool=false;
}

while(whileBool)
{
trace("While Active!"
//make it false now, so it won't repeat
whileBool=false;
}
}

mightybob
offline
mightybob
363 posts
1,060

Thanks it doesn't freeze anymore now I just need him to keep rotating after 180 degrees, so he can go all the way up the loop.

weirdlike
offline
weirdlike
1,309 posts
28,720

angle = heroMC._rotation;

var dx = Math.cos(angle*Math.PI/180);
var dy = Math.sin(angle*Math.PI/180);

in while statement-> angle += 1;

a simple design, I recommend adding a calculation to incorporate speed in case if too slow climb halfway up and fall down, maybe something like

while statement
{
speed -=.1;
angle = angle+speed*1
}

play around with it and see what you get

mightybob
offline
mightybob
363 posts
1,060

Thanks i'll try it out.

mightybob
offline
mightybob
363 posts
1,060

Can't get it to work right... Oh well, if my indiegogo campaign is successful I'll just hire a programmer to make all the loop stuff.

weirdlike
offline
weirdlike
1,309 posts
28,720

giving up doesn't lead to success. Also you are working on a platform game which has it's own set of difficulties and are shooting for FPA which uses impressive coding in itself

re-posting
Flade
Pixel Perfect Collision Detection

I suggest you save your money and shift to as3. Flex is available and is free

as3 links
Box2D
CDK
APE

mightybob
offline
mightybob
363 posts
1,060

I'd be happy to use flade if you could show me a way to make new objects in it without setting X Y coordinates, size, shape, color, all in the code.

I'd like to be able to make objects on the stage and have flade use those, but if that's not possible then flade / ape won't work fir me... also, does Box2d let you use curved terrain, or only boxes?

mightybob
offline
mightybob
363 posts
1,060

sorry, *won't work for me

weirdlike
offline
weirdlike
1,309 posts
28,720

I don't normally code with as2 so I am unfamiliar with how flade and PPCD work

mightybob
I'd like to be able to make objects on the stage and have flade use those, but if that's not possible then flade / ape won't work fir me... also, does Box2d let you use curved terrain, or only boxes?


as for as3 I would recommend using CDK, it fits the bill of exactly what you are saying, when you add the MovieClips to CDK it returns the angle of approach then you can make the appropriate calculations. =98247">HERE is Oneil's post as an example of how to use CDK. On top of the examples from code.google

joeybetz
I code in AS3 as part of my career, but I've dabbled in few other languages over the years. I use FlashDevelop as my go to programming IDE for AS3. It's free (but you should totally donate) and it's awesome.

Good luck and happy coding though.


taken from Betz on Reddit IAmA

FlashDevelop

I hate to sound pushy, but in my opinion as2 is outdated
mightybob
offline
mightybob
363 posts
1,060

Using As3 now, but ran into problems with loading external swfs.

Here's my code:

var loader:Loader=new Loader();

this.addChild(loader);
loader.load(new URLRequest("myfile.swf&quot);

But that just loads my swf over-top of my current one, but I need it to stop the current swf, and replace it with the newly loaded one. Kinda like loadMovie in As2.

weirdlike
offline
weirdlike
1,309 posts
28,720

maybe this...

oldLoader.unloadAndStop();

this.removeChild(oldLoader);

var loader:Loader=new Loader();

this.addChild(loader);
loader.load(new URLRequest("myfile.swf&quot);

mightybob
offline
mightybob
363 posts
1,060

Thanks, but that's not really what I'm looking for.

I need it to not really load it, but go to the swf... loadMovie pretty much did that, but apparently it's not that easy in As3 :l

weirdlike
offline
weirdlike
1,309 posts
28,720

If I am understanding correctly...

//CREATE MOVIE CLIP
var clip:MovieClip=new MovieClip();

//CENTER IT TO STAGE
clip.x=stage.stageWidth/2;
clip.y = stage.stageHeight/2;

//LOAD THE SWF
var loader:Loader=new Loader();
//ADD LOADER TO MOVIECLIP
clip.addChild(loader);
//THIS TOO...
loader.load(new URLRequest("myfile.swf&quot);

//ADD MOVIECLIP
addChild(clip);

mightybob
offline
mightybob
363 posts
1,060

I guess i'm just not explaining it right, but I searched google for hours and came up with nothing I am looking for, I guess i'll give multiple scenes a shot.

Showing 16-30 of 39