ForumsProgramming ForumMaking a faked physics engine in As2?

39 31931
mightybob
offline
mightybob
360 posts
Peasant

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,299 posts
Prince

I have re-read your question and I guess I am not sure what you are asking maybe SS will help. create another topic this one is starting to change

mightybob
offline
mightybob
360 posts
Peasant

I have remade the ENTIRE engine in As3.

Well, he can finally go up loops. (looks a bit sloppy but it does it non the less)

I gave up on writing the rotation part on my own after getting no where for a long time...

Incase if anyone else is going through the hours of researching and failing and flash crashing, here is the code I found:

[i]
function groundAngle(src, dist, tgt){
var hits = true;
var points = new Array();
var total = 0;

for(var i=0; i= 2)break;
}

for(var j=0; j

mightybob
offline
mightybob
360 posts
Peasant

Sorry, armor games posted that weird...

function groundAngle(src, dist, tgt){
var hits = true;
var points = new Array();
var total = 0;

for(var i=0; i= 2)break;
}

for(var j=0; j

mightybob
offline
mightybob
360 posts
Peasant

Okay then... never mind.

Armor games won't post it right

weirdlike
offline
weirdlike
1,299 posts
Prince

yes there are problems with the less than symbol

&lt i have just been typing it out LESSTHANSYMBOL

weirdlike
offline
weirdlike
1,299 posts
Prince

http://weirdlike.tk/backdoor/htmlCodes.jpg

mightybob
offline
mightybob
360 posts
Peasant

Alright, that piece of code I mentioned above didn't work as well as I'd like it to work... So I came up with this:

//this part basically makes a line between start and end symbols
var ang:Number = 0;
if (start.y (less-than-symbol-HERE) end.y)
{
ang = (Math.PI-Math.atan2(end.y-start.y,end.x-start.x))*180/Math.PI;
}

else {
ang = Math.atan2(end.y-start.y,end.x-start.x)*180/Math.PI;
}

//trace the angle of the line
trace(ang);

//if the player is touching the ground set its rotation to ang
if (touchingGround)
{
player.rotation = ang;
}

//keep starts X near player's X
start.x = (player.x - 50)
//keep ends X near player's X
end.x = (player.x + 50)

Of course all that runs every frame I just didn't want to put in all 300 lines of code :P


//now i apply gravity to start and end
stage.addEventListener(Event.ENTER_FRAME, gravEnd);

var gravityE:Number = 0;
var maxJumpE:Number = -20;
var gravAccelE:Number = 2;
var touchingGroundE:Boolean;

function gravEnd(event:Event):void
{
gravityE += gravAccelE;

end.y += gravityE;

if (ground.hitTestPoint(end.x, end.y+5, true))
{
touchingGroundE = true;
}

else {
touchingGroundE = false;
}

while (ground.hitTestPoint(end.x, end.y, true))
{
end.y -= gravAccelE;
gravityE = 0;
}
}

stage.addEventListener(Event.ENTER_FRAME, gravStart);

var gravityS:Number = 0;
var maxJumpS:Number = -20;
var gravAccelS:Number = 2;
var touchingGroundS:Boolean;

function gravStart(event:Event):void
{
gravityS += gravAccelS;

start.y += gravityS;

if (ground.hitTestPoint(start.x, start.y+5, true))
{
touchingGroundS = true;
}

else {
touchingGroundS = false;
}

while (ground.hitTestPoint(start.x, start.y, true))
{
start.y -= gravAccelS;
gravityS = 0;
}
}

Now all that keeps start and end movieclips on the ground but next to the player on the X axis.

But then if you play this once you go up the first hill it starts glitching, but I don't know why.

Is my way of making a line between start and end not right?

ExplosionsHurt
offline
ExplosionsHurt
248 posts
Nomad

Why not just use Pastebin?

weirdlike
offline
weirdlike
1,299 posts
Prince

I suggest the line should be at the base of the characterMC instead of on the ground then make the rotation based on contact with the ground other wise the rotation would be key press

it looks like the angle calculation is making it glitchy i suggest adding a keypress like t then tracing the angle when you press t

also I suggest using one enterFrame loop instead of two enterFrame loops unless if you are planning on removing one

i hope this is helpful

Showing 31-39 of 39