Forums

ForumsProgramming Forum

Making a faked physics engine in As2?

Posted Jun 8, '13 at 12:27pm

mightybob

mightybob

351 posts

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!

 

Posted Jun 8, '13 at 5:13pm

KentyBK

KentyBK

555 posts

I recommend you give this article a look, just to get the basic idea for all your loopy goodness.

 

Posted Jun 8, '13 at 8:25pm

weirdlike

weirdlike

524 posts

Knight

Flade

good luck :)

 

Posted Jun 9, '13 at 1:09pm

mightybob

mightybob

351 posts

@KentyBK That article is just talking about Sonic's "amazingness". And who knows if it's talking about As2, As3, or javascript.

 

Posted Jun 9, '13 at 2:48pm

KentyBK

KentyBK

555 posts

@KentyBK That article is just talking about Sonic's "amazingness". And who knows if it's talking about As2, As3, or javascript.

Uhhhh no. It explains how the game's engine works, including how the game handles slopes and curved surfaces. It's written in pseudocode so that you can adapt it to whatever language you want. It seemed appropriate given that you want to make an engine "like" those games.

I'm not going to post ready-made code, because that's your job.

 

Posted Jun 10, '13 at 5:26pm

mightybob

mightybob

351 posts

I don't want ready made code, or links to ready made code.

 

Posted Jun 11, '13 at 11:51pm

Secretmapper

Secretmapper

740 posts

If not, then KentyBK's link is an amazing resource really.

 

Posted Jun 25, '13 at 10:08pm

mightybob

mightybob

351 posts

Sorry, was just really frustrated.

I looked through the link you gave me, it helped a lot.

So far I got my player to go halfway up the loop, but then because of using "_y -= gravity" to make it so he hits the ground, it makes the player shoot up to the top of the ground. So, I replaced that with: "_y -= Math.sin(_rotation * Math.PI / 180) * gravity;" into a "while" statement. But now whenever the player hits the ground, Flash Player freezes. I have encountered this problem A LOT of times,
and am getting pretty tired of it ruining every fix i come up with. (I tried an "if" statement too, froze Flash Player also).

Will "_y -= Math.sin(_rotation * Math.PI / 180) * gravity;" even work? And if so how can I fix this "while" statement problem?

 

Posted Jun 26, '13 at 12:05am

weirdlike

weirdlike

524 posts

Knight

I'm not sure what the exact calculation would be but you can look at this

speed = 5;
gravity = 2;
angle = MC._rotation;

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

MC.onEnterFrame = function()
{
        this.dy += gravity;
        this._x += this.dx*speed;
        this._y += this.dy*speed;
}

 

Posted Jun 26, '13 at 11:55am

mightybob

mightybob

351 posts

Well, I still have the problem of Flash Player freezing when using my gravity var with math in a while or if statement. I used math.cos and math.sin in other if statements, but for some reason it's freezing in just this one... The only code I used in my while statement was this:

_y -= Math.sin(_rotation * Math.PI / 180) * gravity;
Grav = 0;

And I tried to do so with an if statement too. But it still froze. Tried googling it, could only find as3 results. But then when I just use

Grav = 0;
_y -= gravity;

No freezing, but halfway up the loop the player shoots up.

So I'm pretty sure _y -= Math.sin(_rotation * Math.PI / 180) * gravity; will work, all I need is a fix for flash freezing when I put it In a while statement.

If you need more of my code to help figure out the problem, just let me know.

Ps: if this helps at all, it's not timeline code, it's code inside of a symbol.

 
Reply to Making a faked physics engine in As2?

You must be logged in to post a reply!