Forums

ForumsProgramming Forum

Making a faked physics engine in As2?

Posted Aug 6, '13 at 10:00pm

mightybob

mightybob

351 posts

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.

 

Posted Aug 7, '13 at 1:38pm

weirdlike

weirdlike

475 posts

Knight

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

 

Posted Aug 27, '13 at 10:30am

mightybob

mightybob

351 posts

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

 

Posted Aug 27, '13 at 10:51am

mightybob

mightybob

351 posts

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

 

Posted Aug 27, '13 at 10:59am

mightybob

mightybob

351 posts

Okay then... never mind.

Armor games won't post it right

 

Posted Aug 27, '13 at 11:56am

weirdlike

weirdlike

475 posts

Knight

yes there are problems with the less than symbol

< i have just been typing it out LESSTHANSYMBOL

 

Posted Aug 27, '13 at 12:53pm

weirdlike

weirdlike

475 posts

Knight

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

 

Posted Sep 10, '13 at 6:11pm

mightybob

mightybob

351 posts

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 http://bobmania.com/file/ 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?

 

Posted Sep 10, '13 at 7:43pm

ExplosionsHurt

ExplosionsHurt

247 posts

Why not just use Pastebin?

 

Posted Sep 10, '13 at 7:44pm

weirdlike

weirdlike

475 posts

Knight

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 :)

 
Reply to Making a faked physics engine in As2?

You must be logged in to post a reply!