2019-04-20 09:01:56

I'm trying to make a little game thing for myself, and I want jumping, but i'm having difficulties.

I wasn't sure how to aproach this, so I decided, hey, let's  try to convert Mason's jumping code from his open source projects into 3d.
There were prior changes by myself as well, to make a few parts of the thing act differently.
But for some reason, it won't jump.
Here is the jumping segment, tell me if you need more information. Maybe you can help?: Also, if you could help me with not letting my steps play when I walk off and edge?

void game()
P
while(true)
{
if (key_pressed(KEY_SPACE) and jumping==false and key_up(KEY_G) and jumpstuntimer.elapsed>=jumpstuntime)
{
p.play_stationary("sounds/jump.ogg",false);
ty1=me.z;
ty2=me.z+jumpheight;
jumping==true;
ascending==true;
jumpstuntimer.restart();
}
if (jumping==true)
{
if (atapex==true and jumptimer.elapsed>=apextime)
{
jumptimer.restart();
atapex==false;
}
if (ascending==false and jumptimer.elapsed>=jumptime2 and atapex==false)
{
jumptimer.restart();
me.z-=1;
checkforplatforms();
if (me.z<=ty1)
{
me.z=ty1;
p.play_stationary("sounds/land.ogg",false);
jumping==false;
}
}
if (ascending==true and jumptimer.elapsed>=jumptime)
{
jumptimer.restart();
me.z++;
checkforwalls();
if (me.z>=ty2)
{
ascending==false;
jumptimer.restart();
atapex==true;
}
}
}
if(me.x<0)
{
me.x=0;
}
else if(me.x>maxx)
{
me.x=maxx;
}
else if(me.y<0)
{
me.y=0;
}
else if(me.y>maxy)
{
me.y=maxy;
}
if(key_pressed(KEY_C))
{
speak(""+me.x+", "+me.y+", "+me.z+"");
}
if(jumping==false)
{
movetime=walkspeed;
}
else if(jumping==true)
{
movetime=airspeed;
}
if(key_down(KEY_UP) and movetimer.elapsed>=movetime)
{
move(1);
}
else if(key_down(KEY_RIGHT) and movetimer.elapsed>=movetime)
{
move(2);
}
else if(key_down(KEY_DOWN) and movetimer.elapsed>=movetime)
{
move(3);
}
else if(key_down(KEY_LEFT) and movetimer.elapsed>=movetime)
{
move(4);
}
if(key_pressed(KEY_ESCAPE))
{
p.destroy_all();
mainmenu();
}
}
wait(5);
}
void move(int dir)
{
movetimer.restart();
if(me.z==0)
{
p.play_stationary("sounds/step"+random(1,5)+".ogg",false);
}
if(dir==1)
{
me.y++;
}
else if(dir==2)
{
me.x++;
}
else if(dir==3)
{
me.y-=1;
}
else if(dir==4)
{
me.x-=1;
}
}
----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-04-20 09:46:24 (edited by ogomez92 2019-04-20 09:49:41)

You got it all wrong
Instead of trying to just convert code to 3d like you are doing, ask yourself this:
How can I jump?
Answer your own question, instead of using someone else's code without knowing what it does.

There is no absolute truth to a piece of code, just like there is no absolute religion that works for everyone.
there are always many ways to do something.
Think about the possible solutions. In bgt you have booleans, timers, and position variables. How can you jump?
You need a status variable to see if you are jumping or not, then a timer to see how long you are jumping.
If its 3d, it's probably  more complex than that, so Mason's code won't help you.
3d needs realistic jumping, as in, it needs to go through a given number of positions up/down as the timer progresses.
Try using a few different approaches, see if you grasp the concept.
Anyway, this code you provide is so convoluted.
checkforwalls, checkforplatforms, etc needs to be put in a single function that checks your position against collisions with static and dynamic objects.

Hth.

ReferenceError: Signature is not defined.

2019-04-20 13:35:14 (edited by kianoosh 2019-04-20 13:36:02)

Plus. Dude. == is for comparrison and = is for setting a value. So actually atapex==true; should be atapex=true;
3d position is usually a vector with x, y and z axis so in this case you have to change the z value instead of y, and you have to simulate jumping in your mind. When you jump, you first go upwards, then fall downwards and while falling downwards, unless the height changes when you're falling, You have control over yourself so when falling and the height is still the same, you shouldn't get hurt after reaching the ground

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2019-04-20 13:56:41

oh yeah I missed that one.

ReferenceError: Signature is not defined.

2019-04-20 16:59:32

hmm, I will think on this.
I'm really not sure where to start, but let's see where I get.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-04-20 18:30:45

Ok, I'm making some progress. One issue though. For some reason, this code only puts me up 1 tile and then just leaves me hangin. It's probably vary simple why it happened but, I don't know right now. Any ideas?

if(key_pressed(KEY_SPACE) and me.z==0 and jumpstuntimer.elapsed>=jumpstuntime and jumping==false)
{
jumping==true;
p.play_stationary("sounds/jump.ogg",false);
if(me.z<5 and risetimer.elapsed>=risetime)
{
risetimer.restart();
me.z+=1;
}
}
----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-04-20 20:42:30 (edited by amerikranian 2019-04-20 22:24:01)

/*I will comment the lines with the comment above the line. For example, consider this to be the comment about the if statement*/
if(key_pressed(KEY_SPACE) and me.z==0 and jumpstuntimer.elapsed>=jumpstuntime and jumping==false)
{
//Your first issue: the 2 equal signs check for equality of an object, jumping in this case. Change this to jumping=true;
jumping==true;
p.play_stationary("sounds/jump.ogg",false);
//This is also an issue: It is inside the jumping statement, and thus, won't be triggered when jumping equals true.
if(me.z<5 and risetimer.elapsed>=risetime)
{
risetimer.restart();
me.z+=1;
}
}
/*Consider adding in a third boolean as well as another jumping timer that keeps track of how long you're gonna be in the air. If you don't, you'll continue to rise until you reach 5 and just hang there, unless you add in the if statement that checks for the equality of player's z coordinate to the max height. That'll get rid of your timer, but you'll still need another boolean to not start randomly falling.
Also, consider Adding platform and wall detection within your jump, as right now you'll magically glide through anything until you reach 5.
Final note: Consider avoding pre-set values for your jumping height. Your jumps will only work if the player is below 5, limiting you to platforms within that range.
I will do you a favor and fix the code, just because I feel nice today. If you wish to try on your own, skip the rest of this post.
if(key_pressed(KEY_SPACE) and me.z==0 and jumpstuntimer.elapsed>=jumpstuntime and jumping==false)
{
jumping=true;
p.play_stationary("sounds/jump.ogg",false);
}
if(jumping==true) //Necessary for the bgt engine to skip over this when a player is just walking. Makes it nicer for BGT overall IMO.
{
if(me.z<5 and risetimer.elapsed>=risetime)
{
risetimer.restart();
me.z+=1;
}
}

2019-04-21 00:15:48

The  game in question is not vary in depth, and won't have platforms above 0... As of now.
I'm taking this one stage at a time, so I'll make the descending loop next.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-04-21 00:31:01

Hi.
It works thanks.
Now, I have my descending and landing ideas, but this doesn't quite work, would you mind helping me again? This should be the last time.

if(key_pressed(KEY_SPACE) and me.z==0 and jumpstuntimer.elapsed>=jumpstuntime and jumping==false)
{
jumping=true;
p.play_stationary("sounds/jump.ogg",false);
}
if(jumping==true)
{
if(me.z<5 and risetimer.elapsed>=risetime)
{
risetimer.restart();
me.z+=1;
ascending=true;
}
if(me.z>=5 and ascending==true)
{
ascending=false;
}
if(me.z>1 and ascending==false and risetimer.elapsed>=risetime)
{
risetimer.restart();
me.z-=1;
}
if(me.z==1 and risetimer.elapsed>=risetime)
{
jumping=false;
p.play_stationary("sounds/land.ogg",false);
me.z=0;
}
}

One other thing:
I allow walking with the four arrows, but I don't want them to go into negative coordinates obviously, but I also don't want it to play a sound when you step off an edge. Here is my code, and maybe you could help me?:

if(me.x<0)
{
me.x=0;
}
else if(me.x>maxx)
{
me.x=maxx;
}
else if(me.y<0)
{
me.y=0;
}
else if(me.y>maxy)
{
me.y=maxy;
}
if(key_pressed(KEY_C))
{
speak(""+me.x+", "+me.y+", "+me.z+"");
}
if(jumping==false)
{
movetime=walkspeed;
}
else if(jumping==true)
{
movetime=airspeed;
}
if(key_down(KEY_UP) and movetimer.elapsed>=movetime)
{
move(1);
}
else if(key_down(KEY_RIGHT) and movetimer.elapsed>=movetime)
{
move(2);
}
else if(key_down(KEY_DOWN) and movetimer.elapsed>=movetime)
{
move(3);
}
else if(key_down(KEY_LEFT) and movetimer.elapsed>=movetime)
{
move(4);
}
if(key_pressed(KEY_ESCAPE))
{
p.destroy_all();
mainmenu();
}
}
wait(5);
}
void move(int dir)
{
movetimer.restart();
if(me.z==0)
{
p.play_stationary("sounds/step"+random(1,5)+".ogg",false);
}
if(dir==1)
{
me.y++;
}
else if(dir==2)
{
me.x++;
}
else if(dir==3)
{
me.y-=1;
}
else if(dir==4)
{
me.x-=1;
}

Thanks...

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-04-21 02:39:32 (edited by amerikranian 2019-04-21 02:57:51)

I'm not sure if this will help, but here we go:
if(key_pressed(KEY_SPACE) and me.z==0 and jumpstuntimer.elapsed>=jumpstuntime and jumping==false)
{
jumping=true;
p.play_stationary("sounds/jump.ogg",false);
}
if(jumping==true)
{
//I'm assuming your character is floating in the air. This is a problem. You're setting the variable to true, add in the z, then set it to false and continue floating. The condition doesn't trigger because the risetimer has just been restarted.
if(me.z<5 and risetimer.elapsed>=risetime)
{
risetimer.restart();
me.z+=1;
ascending=true;
}
if(me.z>=5 and ascending==true)
{
ascending=false;
}
if(me.z>1 and ascending==false and risetimer.elapsed>=risetime)
{
risetimer.restart();
me.z-=1;
}
if(me.z==1 and risetimer.elapsed>=risetime)
{
jumping=false;
p.play_stationary("sounds/land.ogg",false);
me.z=0;
}
}
//The movement code is simple. I like your function, but we can simplify it by checking if the player's coordinates are less or greater than the minimum or maximum of the field. I'll provide the fixed code, hopefully... Here goes the jump code
if(key_pressed(KEY_SPACE) and me.z==0 and jumpstuntimer.elapsed>=jumpstuntime and jumping==false)
{
jumping=true;
ascending=true;
p.play_stationary("sounds/jump.ogg",false);
}
if(jumping==true)
{
if(risetimer.elapsed>=risetime)
{
risetimer.restart();
if(ascending==true)
{
me.z++;
if(me.z>=5 and ascending==true)
{
ascending=false;
}
}
else
{
me.z-=1;
if(me.z==0)
{
jumping=false;
p.play_stationary("sounds/land.ogg",false);
me.z=0;
}
}
}
//I haven't ran this, simply because I kind of don't care for writing the class for a player in bgt, but hopefully this will work. I might have forgotten a brace, but try it out.
//Here's the movement code:
//Remove the if me.x<0 and the other three ifs at the beginning of your code chunk.
//Have a variable that checks if a player actually moved, and if so, play a sound. I won't write that part, I'm sure you can handle it.
bool move(int dir)
{
movetimer.restart();
if(dir==1 and me.y<max)
{
me.y++;
return true;
}
else if(dir==2 and me.x<maxx)
{
me.x++;
return true;
}
else if(dir==3 and me.y>0)
{
me.y-=1;
return true;
}
else if(dir==4 and me.x<0)
{
me.x-=1;
return true;
}
return false;
}

Code aside, this is a problem, Redfox. You need to learn how to debug your code. I'm not gonna be there to sit down and give you ideas as to where and how you screwed up. More over, if I do so, I may not always provide solutions to your issue. If you can't debug something you're making, step down. Build a simpler project. I'm not criticizing you, I'm just giving you some advice. You'll thank me later, trust me.

2019-04-21 04:37:27

@10, I know, I was wracking my brain to try to figure out why it wasn't working and I wasn't really sure.
I'm trying to start smaller and I thought this would be relatively simple but I guess not?

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-04-26 03:44:01

Based on all this, I have created a jump function, problem now is that I don't actually ascend above ground. I used to be able to, but I would not properly descend. When I threw the falling bool into the equation, I never was able to properly ascend. Here's the code:
if (key_pressed(KEY_SPACE) and jumping==false and me.z==0 and jumptimer.elapsed>=jumptime and falling==false)
{
jumping=true;
ascending=true;
p.play_stationary("sounds/jump.ogg",false);
tempz1=me.z;
tempz2=6;
ascending=true;
}
if (jumping==true)
{
if (risetimer.elapsed>=risetime)
{
risetimer.restart();
if (ascending==true and me.z<=tempz2)
{
me.z+1;
if (ascending=true and me.z>=tempz2)
{
ascending=false;
falling=true;
}
}
if(ascending==false and falling==true)
{
me.z-=1;
if (me.z<0)
{
jumping=false;
falling=false;
me.z=0;
playland();
jumptimer.restart();
jumptimer.pause();
risetimer.restart();
risetimer.pause();
}
}
}
}