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]
@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.
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?
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:
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.
So I'm pretty sure _y -= Math.sin(_rotation * Math.PI / 180) * gravity; will work
I'm not sure it does, what do you WANT it to do? Right now, _y won't decrease at all when _rotation is 180 or 0 degrees. Similarly, it evaluates to _y -= gravity and _y -= - gravity for 90 and 270 degrees, respectively.
If you need more of my code to help figure out the problem, just let me know.
I'd suggest posting the condition inside your while statement and most of the relevant code, simply because it's always easier to read in context .
Here is my code I wrote: (all of this is inside my symbol with the instance name of "char"
onClipEvent(load) { var speed:Number = 0; var maxSpeed:Number = 23; var char:MovieClip = _root.char; var grav:Number = 0; var gravity:Number = 2; var touchingGround:Boolean; var hittingWall:Boolean; var leftOrRightDown:Boolean = false; var ground:MovieClip = _root.ground; var boolean:Boolean; var otherBoolean:Boolean; var maxJump:Number = -30; var collision:Boolean; var collision2:Boolean; var wall:MovieClip = _root.wall; var leftJumpReady:Boolean; var rightJumpReady:Boolean; }
onClipEvent(enterFrame) { _y += grav; grav += Math.cos(_rotation * Math.PI / 180) * gravity; grav += Math.sin(_rotation * Math.PI / 180) * gravity; if (leftJumpReady && touchingGround == false) { if(grav > 0) { grav -= 1; } if(Key.isDown(Key.SPACE)) { speed = -20; grav = maxJump; } } while (ground.hitTest(_x, _y, true)) { grav = 0; } if (ground.hitTest(_x+5, _y+5, true)) { touchingGround = true; } if (ground.hitTest(_x, _y, true)) { touchingGround = true; } else { touchingGround = false; } this is the while statement making it freeze while (ground.hitTest(_x, _y, true)) { _y -= Math.sin(_rotation * Math.PI / 180) * gravity; }
otherSide is the left side of char, side is the right side of char.
collision2 and collision booleans are to check if side or otherSide are hitting ground.
ground is the instance name of my ground symbol... Obviously.
And what I am trying to get it to do is:
I want the player to be able to go up crazy ramps, sorta like in the Fancy Pants Adventures. (see linked image below)
And also what I am trying to do is jump at angles, because if I figure out how to do this whole crazy ramp thing not being able to jump at angles will cause a big problem.
A link to a tutorial or any help would be great.
Thanks!
(PS: just ignore rightJumpReady and leftJumpReady, it's just my failed attempt at wall jumps)