Be a Supporter!

Depths + Jumping = shit

  • 590 Views
  • 3 Replies
New Topic Respond to this Topic
jotendo
jotendo
  • Member since: Nov. 25, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Depths + Jumping = shit Jun. 23rd, 2009 @ 09:32 PM Reply

hey,
I've got a problem with depths and jumping.

Basically the depth of the player and enemies is figured by the _y
so if the player is further down the screen he will be infront.

Now that I've added jumping, its all gone to shit because of the _y value changing during the jumping.

I know that I can make the depth changing false if jumping is true, but then that screws up when you jump forward and backward on the Y Axis

Here is an example of my problem:
http://spamtheweb.com/ul/upload/240609/4 1452_jumping.php

And the following is the code for the enemy:

onClipEvent (load) {
movespeed = 3;
movespeed2 = 2;
scale = _xscale;
}
onClipEvent (enterFrame) {
distancex= this._x-_root.player._x;
distancey= this._y-_root.player._y;
if(distancex < 160 && distancex > 70 && distancey < 150){//if the distance between player and enemy is between 160 and 100... (to increase or descrease max and min range, just increase or decrease the numbers)
_xscale = -scale;
_x-=movespeed;//make the enemy walk towards the player. Increase number to increase enemy's speed.
}
if(distancex > -160 && distancex < -70 && distancey < 150){//if the distance between player and enemy is between -10 and -160... (to increase or descrease max and min range, just increase or decrease the numbers)
_xscale = +scale;//turn the enemy in the proper direction
_x+=movespeed;//make the enemy walk towards the player. Increase number to increase enemy's speed.
}
if(distancey < 100 && distancey > 10 && distancex < 40){//if the distance between player and enemy is between 160 and 100... (to increase or descrease max and min range, just increase or decrease the numbers)
_xscale = -scale;
_y-=movespeed2;//make the enemy walk towards the player. Increase number to increase enemy's speed.
}
if(distancey > -100 && distancey < -10 && distancex < 40){//if the distance between player and enemy is between -10 and -160... (to increase or descrease max and min range, just increase or decrease the numbers)
_xscale = +scale;//turn the enemy in the proper direction
_y+=movespeed2;//make the enemy walk towards the player. Increase number to increase enemy's speed.
}
}
onClipEvent (enterFrame) {
thisDepth=this.getDepth(), otherDepth=_root.player.getDepth();
if (_y>_root.player._y && otherDepth>thisDepth) {
this.swapDepths(_root.player);
}
if (_root.player._y>_y && thisDepth>otherDepth) {
this.swapDepths(_root.player);
}
}
onClipEvent(load) {
this._x=random(550);
this._y=226+random(274);
}
onClipEvent(load){

Dead = false;

}

And the player code as well:

onClipEvent (load) {
speed = 3;
speed2 = 2;
y_start = _y;
jumping = false;
jumpspeed = 0;
run= false;
scale = _xscale;
}
onClipEvent (enterFrame) {
if ((Key.isDown(Key.RIGHT))) {
if(jumping==true) {
this.gotoAndStop(5);
} else {
this.gotoAndStop(2);
}
this._x += speed;
run=true;
_xscale = +scale;
}
if ((Key.isDown(Key.LEFT))) {
if(jumping==true) {
this.gotoAndStop(5);
} else {
this.gotoAndStop(2);
}
this._x -= speed;
run=true;
_xscale = -scale;
}
if ((Key.isDown(Key.UP))) {
if(jumping==true) {
this.gotoAndStop(5);
} else {
this.gotoAndStop(2);
}
this._y -= speed2;
y_start-= speed2;
run=true;
}
if ((Key.isDown(Key.DOWN))) {
if(jumping==true) {
this.gotoAndStop(5);
} else {
this.gotoAndStop(2);
}
this._y += speed2;
y_start+=speed2;
run=true;
}

if (Key.isDown(65) && run==false) {
this.gotoAndStop(4);
}
if (jumping) {
_y += jumpspeed;
jumpspeed += 1;
if (_y>=y_start) {
_y = y_start;
jumping = false;
this.gotoAndPlay(1);
_root.jump=false;
}
} else {
if (Key.isDown(83)) {
jumping = true;
jumpspeed = -10;
_root.jump=true;
this.gotoAndStop(5);
}
}
}
onClipEvent(keyUp) {
run=false;
if(jumping==false) {
this.gotoAndPlay(1);
}
}

Please help!
Thanks!!

Coolio-Niato
Coolio-Niato
  • Member since: Jun. 30, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to Depths + Jumping = shit Jun. 23rd, 2009 @ 10:41 PM Reply

Didnt read the code. next time dont post all of it.

I do though know what you have to do. Set a variable that tracks the y position on the screen. Set another one that tracks the jump height at that moment. Let the character's y position be a combination of the two (ypos+jumpPos), but the depths depend only on the first variable (ypos).

Ez.

jotendo
jotendo
  • Member since: Nov. 25, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Depths + Jumping = shit Jun. 23rd, 2009 @ 10:47 PM Reply

At 6/23/09 10:41 PM, Coolio-Niato wrote:

::

okay cool
will that work if I jump backwards over an enemy? or diagonal

Coolio-Niato
Coolio-Niato
  • Member since: Jun. 30, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to Depths + Jumping = shit Jun. 24th, 2009 @ 02:27 PM Reply

At 6/23/09 10:47 PM, jotendo wrote:
At 6/23/09 10:41 PM, Coolio-Niato wrote:
okay cool
will that work if I jump backwards over an enemy? or diagonal

yes.