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]
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;
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