May 22, 2012, 12:00:26 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Prowlie Welcome back! The site migration is complete and normal service resumed.
Advanced search
Pages: [1]   Go Down
Print
Author Topic: new problem.....  (Read 958 times)
0 Members and 2 Guests are viewing this topic.
whistlingboy
Woodfolk
*
Offline Offline

Gender: Male
Posts: 39


I want to animate forever......


WWW
« on: February 08, 2009, 03:24:36 AM »

ok. this is really annoying me. can someone tell me why my player dosent stand on top of the ground???

this is the whole code for the player..

Code:
onClipEvent (load) {
var speed:Number = 0;
var walk:Number = 10;
var run:Number = 20;
var grav:Number = 0;
var falling:Number = 0;
var jumped:Boolean = false;
var jumpHeight:Number = 20;
var touchingGround:Boolean = false;
var scale:Number = _xscale;
var doorOpened:Boolean = false;
var attacked:Boolean = false;
}
onClipEvent (enterFrame) {
if (!touchingGround) {
grav++;
this._y += grav;
} else {
grav = 0;
}
if (_root.ground.hitTest(_x, _y, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (!attacked) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
this.gotoAndStop(2);
_xscale = +scale;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
this.gotoAndStop(2);
_xscale = -scale;
}
if (Key.isDown(Key.SHIFT)) {
speed = run;
} else {
speed = walk;
}
}
}
onClipEvent (enterFrame) {
if (!attacked) {
if (jumped) {
falling += 0.5;
_y += falling;
if (touchingGround) {
jumped = false;
}
} else {
if (Key.isDown(Key.UP)) {
jumped = true;
falling = -jumpHeight;
this.gotoAndStop(3);
}
}
}
if ((Key.isDown(Key.UP)) and (Key.isDown(Key.LEFT))) {
this.gotoAndStop(3);
}
if ((Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) {
this.gotoAndStop(3);
}
if ((!Key.isDown(Key.UP)) and (!touchingGround)) {
this.gotoAndStop(3);
} else if ((Key.isDown(Key.UP)) and (!touchingGround)) {
this.gotoAndStop(3);
}
if ((_currentframe == 3) and (touchingGround)) {
gotoAndStop(1);
}
}
onClipEvent (keyUp) {
if (!attacked) {
gotoAndStop(1);
}
}
onClipEvent (enterFrame) {
if ((this.hitTest(_root.door)) and (!doorOpened)) {
this._x += speed;
}
if ((this.hitTest(_root.door)) and (Key.isDown(Key.SPACE)) and (_root.keys>= 1)) {
this.gotoAndStop(2);
doorOpened = true;
_root.keys -= 1;
}
if (this.hitTest(_root.wall)) {
this._x += speed;
}
if (this.hitTest(_root.key)) {
_root.keys += 1;
unloadMovie(_root.key);
}
if (_root.keys<0) {
_root.keys = 0;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(65)){
attacked = true;
this.gotoAndStop(4);
if(this.hitTest(_root.enemy)) {
_root.enemy.unloadMovie();
}
}
}
onClipEvent (enterFrame) {
if (Key.isDown(65)){
attacked = true;
this.gotoAndStop(4);
if(this.hitTest(_root.enemy2)) {
_root.enemy2.unloadMovie();
}
}
}

 Huh?




ps. how do i put the swf up here for you to see?


cheers all...

Logged

Vector
Resident Actionscript Guru
Assistant Admin
Heroic
****
Offline Offline

Gender: Male
Posts: 3803


~ Programmer | National Laser Tag Player | Bent ~


WWW
« Reply #1 on: February 09, 2009, 01:51:28 PM »

I suspect the problem lies in your ground MovieClip.

If it's not high enough, it is possible that before you add gravity, the player is just above the ground, and after you add gravity, the player is just below the ground.

A more appropriate solution to solve this problem is to project ("predict") a line showing where they player is before you add gravity and where the player is after you add gravity, and see if that line digs into the ground at all.

The simplest implementation of that is using y = mx + c, where you know x1,y1 to be "before gravity" and x2,y2 to be "after gravity". Stick those values in to get your first equation.
Then, use y = mx + c again for a second equation, this time x1,y1 is the left end of your ground, and x2y2 is the right end of your ground.

I won't continue with more math here, however if you do want an example you can look at this Line Segment Intersection Article (which I have used before and found it to be very useful).

There's also some links to things like sweep line algorithms on wikipedia articles referring to Line Segment Intersection that you may want to check out, if your ground is not flat the entire way across. Smiley
Logged

~Vector
Brackenwood
   

 Logged
Pages: [1]   Go Up
Print
Jump to:  

Theme by Pieter, based on Black Rain by Crip Powered by SMF 1.1.16 | SMF © 2011, Simple Machines XHTML | CSS

Page created in 0.044 seconds with 24 queries.