PDA

View Full Version : more jumping problems



Dhryn
May 7th, 2006, 10:28 AM
I can now get my character to jump, and fall, as if there was gravity, but he/she falls into the platforms, which means that you can move sideways without jumping.

no idea why it is doing this, any help would be great.

35783

35784

Dhryn
May 7th, 2006, 11:56 AM
arrow keys to move around

InfestedDemon
May 7th, 2006, 12:04 PM
i accenidently deleted the jumping but i made it better. :D

EDIT: I did what the guy above me said. All you need to do know is ad jump code.

Joppe
May 7th, 2006, 12:05 PM
Personally I would say go hittest with shapeflag, partly becouse that is what I know. I am not familiar with getBounds, never got around learning it..
And well your code could look like


while(_root.ground.hitTest(this._x,this._y-1,true)){
this._y --;
falling = false
//etc
}


But hey, your call.
Play with it :)

Dhryn
May 7th, 2006, 12:09 PM
joppe, could you explain where I would put that and how to use it, I only used getbounds because that is what I know, I'm not bothered how it is done aslong as it works properly.

InfestedDemon
May 7th, 2006, 12:11 PM
joppe, could you explain where I would put that and how to use it, I only used getbounds because that is what I know, I'm not bothered how it is done aslong as it works properly.

1. lol, like the matrix.

2. Well, your stupid. You should know. Use mine and add jump code. Thats MY maximum help, and i think joppe has just given the code because you SHOULD know what to do, noob.

Joppe
May 7th, 2006, 12:21 PM
^Wtf is like wrong with you dude? You ask for help all the time all the day, and now your clanking down on other people? Like wtf :/

Just replace the previous getbounds code for the hittest with ground with the code i posted and well the only thing you need to have except the old code is this._y --; and yeah the hittest of course :)


while(_root.ground.hitTest(this._x,this._y-1,true)){
this._y --;
// then your old code
}

Dhryn
May 7th, 2006, 12:57 PM
thx for your help joppe, I have tried the code you gave me and it works, but, I want the character to stay still in the middle of the stage, then the stage moves around them, which this jump does sept for the this._y--;
when using this the code pushes him up and therefore will eventualy push him off the stage.
I tried reversing it to move the stage but it went weird.

here is what it does 35791

Joppe
May 7th, 2006, 01:08 PM
mmm.. Actually yes I do not have an answer for that.. :/

Nich
May 7th, 2006, 01:58 PM
what I use for that is:
ActionScript Code:

_root._x = 225 - _root.char.clip._x
_root._y = 200 - _root.char.clip._y




You will need to change the names, and the values, but the idea is the same. Set the stage's x and y centered around the character.

Edit: In case I wasn't clear enough, change char.clip to whatever you've named your character, and the 225/200 to whatever your width and height are divided by 2

Dhryn
May 7th, 2006, 02:39 PM
doesnt that code centre the stage around the character?

InfestedDemon
May 7th, 2006, 02:50 PM
^Wtf is like wrong with you dude? You ask for help all the time all the day, and now your clanking down on other people? Like wtf :/

Just replace the previous getbounds code for the hittest with ground with the code i posted and well the only thing you need to have except the old code is this._y --; and yeah the hittest of course :)
ActionScript Code:

while(_root.ground.hitTest(this._x,this._y-1,true)){
this._y --;
// then your old code
}



Damn, i guess my jokes aren't that recognisable, kirupa is dedicated to help :p of corse i will hlpe. that was a mere joke.

Smee
May 7th, 2006, 08:31 PM
I suppose this is supposed to be a continuation of this thread:
http://www.kirupa.com/forum/showthread.php?t=218669

Not sure why a new one was created. Anyway, I think the problem here is that all our suggestions to Dhryn involve moving the character, when his code is actually moving the ground and keeping the character in one place.

Nich
May 7th, 2006, 10:11 PM
doesnt that code centre the stage around the character?
Indeed, which is more or less what you want, no?

Dhryn
May 8th, 2006, 04:27 AM
No, I want the character to stay still, in the centre of the stage, doesnt move.
The stage moves around the character giving the effect of the character moving but there not.
I have movement for my character for left and right
I am just having trouble with the jump, or more accuratly, once the character has jumped (which is really just the stage moving) they fall through the ground (or the ground falls through them, which ever way you want to look at it)

I have seen this done on other games but I dont know how they did it.

Thx for peoples help so far, I dont think I explained my problem very well.

Smee
May 8th, 2006, 04:39 AM
Yeah, you'll just need to apply the code given to you to the stage rather than the character. The same rules apply, just make it move the ground.

Dhryn
May 8th, 2006, 05:16 AM
I tried doing that and it doesnt work, I did post it before but, here is what happens when I changed it around

35802

35803

Although, I probably havent changed it correctly.

nathan99
May 8th, 2006, 07:01 AM
delete all your code on the ball...
give it the instance name "ball"

on the frame put


var speed:Number = 10;
var jump:Number = 15;
var ysp:Number = 0;
ball.onEnterFrame = function() {
if (!ground.hitTest(this._x, this._y-1, true) && !jumping) {
this._y -= ysp--;
}
if (jumping) {
this._y -= jump--;
}
while (ground.hitTest(this._x, this._y-1, true) && jump<=0) {
this._y--;
jumping = ysp=0;
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
} else if (Key.isDown(Key.RIGHT)) {
this._x += speed;
}
if (Key.isDown(Key.UP) && !jumping) {
jumping = jump=15;
}
_y = (Stage.height/2)-this._y;
};

Dhryn
May 8th, 2006, 08:07 AM
that works fantastically, thank you very much

nathan99
May 8th, 2006, 08:20 AM
;)

Joppe
May 8th, 2006, 11:55 AM
Nathan.. The only code needed from your code is the _y = (Stage.height/2)-this._y

great code by the way :)
I'll be using this if thats ok :)

Dhryn
May 8th, 2006, 12:11 PM
Coild some one explain this code to me please. I have started looking at functions but dont properly understand them yet.

Joppe
May 8th, 2006, 01:26 PM
I'll try..


// This are the variables, starting on var which means variable
// And :Number that means it is an number
// var speed:Number = 10; is the same as speed = 10;
var speed:Number = 10;
var jump:Number = 15;
var ysp:Number = 0;
// This is the onEnterFrame = function, which is the same as //onClipEvent(enterFrame) but its is used on the timeline..
ball.onEnterFrame = function() {
// This is hittest with an shapeflag, it is hittest that hittest with the //registration point instead of the bounding box
if (!ground.hitTest(this._x, this._y-1, true) && !jumping) {
// This brings the y location of the movieclip up, ysp-- I have no idea what
// that does :P
this._y -= ysp--;
}
if (jumping) {
// This does the same as ^
this._y -= jump--;
}
// This is an while loop which pulls up the character over ground so it doesnt
// Stuck half way down
while (ground.hitTest(this._x, this._y-1, true) && jump<=0) {
this._y--;
jumping = ysp=0;
}
// Simple movement code..
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
} else if (Key.isDown(Key.RIGHT)) {
this._x += speed;
}
// Jumping code, jumping = 15 might seem weird but this is an short way
// of writing jumping = true
// which is the same as jumping = 1
// I think :P
if (Key.isDown(Key.UP) && !jumping) {
jumping = jump=15;
}
// This converts this._y to the stage._y :)
_y = (Stage.height/2)-this._y;
};

Joppe
May 8th, 2006, 01:28 PM
Note ^ This might not be the correct explanation but its what I think and know of :P

Dhryn
May 8th, 2006, 01:44 PM
Thx, I think I got most of that, I was trying to change it slightly so that other items can be stationary on the stage like the lives and score boxes, just wondering how the code stops the ball from moving even when in the enterframe it seems to be refering to the ball, and in the jump code it seems to applie to the ball, yet the ball doesnt move.

Kinda confused, I dont really understand jumping code that well it seems

Joppe
May 8th, 2006, 03:34 PM
// This converts this._y to the stage._y :)
_y = (Stage.height/2)-this._y;

See when refering to ball and this._y
it changes that with this code and makes it refer to the screen :)

Dhryn
May 8th, 2006, 03:46 PM
so it kinda says, everything but the ball?
If so, is there a way to stop other movie clips on the screen moving?

Thx again for your help and putting up with my questions

Joppe
May 13th, 2006, 02:04 PM
Ahum.. Yes this seems to have stumped me.. I am sorry but i cant help you :/

SacrificialLamb
May 13th, 2006, 08:04 PM
I don’t know function() very will so I made it a onClipEvent so if you take it off the Frame and add it to the ball. I have named the thing/things that should not move “dont_move” on the _root so if you just put all thing that you do not want to move in a moveclip named dont_move or add script referring to whatever you named it where I have some thing referring to “_root.dont_move._y” (you can just use find for this).
Hope thins works ok for you



onClipEvent (load){
var speed:Number = 10;
var jump:Number = 15;
var ysp:Number = 0;
}
onClipEvent (enterFrame) {
_root.dont_move._y = Stage.height-_root._y-100

if (!_root.ground.hitTest(_root.ball._x, _root.ball._y-1, true) && !jumping) {
_root.ball._y -= ysp--;
_root.dont_move._y -= ysp--;

}
if (jumping) {
_root.ball._y -= jump--;
_root.dont_move._y -= jump--;
}
while (_root.ground.hitTest(_root.ball._x, _root.ball._y-1, true) && jump<=0) {
_root.ball._y--;
_root.dont_move._y--;
jumping = ysp=0;
}
if (Key.isDown(Key.LEFT)) {
_root.ball._x -= speed;
} else if (Key.isDown(Key.RIGHT)) {
_root.ball._x += speed;
}
if (Key.isDown(Key.UP) && !jumping) {
jumping = jump=20;
}
_root._y = (Stage.height/2)-_root.ball._y
}

nathan99
May 13th, 2006, 09:22 PM
Check here lamb
http://www.n99creations.com/?pID=tutorials&col=Blue&tut=basics_of_actionscript_for_flash&p=6&l=Flash_MX_04

SacrificialLamb
May 14th, 2006, 01:30 AM
thanks i have not had time to read all of it but it look's to be more manageable than some of the other tutorials about the same thing that start a bit above where I am at