Script47 Posted June 12, 2014 Posted June 12, 2014 (edited) So I decided to try something (which I haven't tried before) I have *attempted* to make gravity/jumping, it can be a big part of quite a few games (I mean who doesn't like jumping). It isn't perfect but I thought it was decent for first attempt. So gimmie your ideas, what you think. And any other advice. Edit 1: Any ideas how I could cap the insane jumping time? So user can't just keep hold of it and halo jump forever? I tried a counter but that had unexpected (and quite annoying) results. Jumping Effect (Gravity) Edited June 12, 2014 by Script47 Quote
gamble Posted June 12, 2014 Posted June 12, 2014 Im not near a jQuery expert but did you just try the key up function for the spacebar rather than both the keyup and keydown? Quote
Script47 Posted June 12, 2014 Author Posted June 12, 2014 Im not near a jQuery expert but did you just try the key up function for the spacebar rather than both the keyup and keydown? I am not using jQuery, I'm using plain JavaScript. No other libraries - jQuery is a library of JavaScript. I'm trying to keep it JavaScript only. As for the second part, no. Because the flow of the example runs like this: Code checks if user is pressing up key (keydown) If key is pressed (keydown still) and has not been released (keyup) then we move upwards However if key has been released (keyup) then we introduce gravity If I did keyup it would move the target (in this case the black square) after you have released the key which is not how it goes. I'm not sure if that's clear enough but tell me if it isn't I'll try explain better. Thanks for the idea anyway. :) Quote
gamble Posted June 12, 2014 Posted June 12, 2014 I meant Javascript haha. thought i would try to help though! Sorry i couldnt help you out! Quote
Dayo Posted June 13, 2014 Posted June 13, 2014 You can set a timeout on key-down that after it has run it stop the event then starts the gravity Quote
Dave Posted June 13, 2014 Posted June 13, 2014 Looks good! Find it weird that you have to hold down the space bar to continue jumping. You should set a fixed height for each jump. Quote
Script47 Posted June 13, 2014 Author Posted June 13, 2014 Looks good! Find it weird that you have to hold down the space bar to continue jumping. You should set a fixed height for each jump. Yes, I have been given an idea from someone which I am going to try. Which basically is a variable with a bool value set by default as true, this check if you're on the ground, when you jump it will turn false and you won't be able to jump again until that value is set to false. Quote
Dave Posted June 13, 2014 Posted June 13, 2014 Yes, I have been given an idea from someone which I am going to try. Which basically is a variable with a bool value set by default as true, this check if you're on the ground, when you jump it will turn false and you won't be able to jump again until that value is set to false. That'd work! Providing the variable never comes out of sync. A potentially better (less hackable, but slightly more intensive way) would be to simply check the users position on the view. If it's not 0 (presuming this is the floor) they're jumping! Quote
wrux Posted June 13, 2014 Posted June 13, 2014 Why not do it so on jump you set a vertical velocity (-v, up) and decrement it to (+v, down) & in your loop you can just do velocity.y += gravity with gravity being some float. My idea wasn't tested but I can't see why it won't work. You need to think about the logic of an actual jump and program it that way. Quote
ColdBlooded Posted June 13, 2014 Posted June 13, 2014 Good stuff I've seen in a while: http://tridiv.com/ and http://www.playfuljs.com/a-first-person-engine-in-265-lines/ Quote
Veramys Posted June 13, 2014 Posted June 13, 2014 Good stuff I've seen in a while: http://tridiv.com/ and http://www.playfuljs.com/a-first-person-engine-in-265-lines/ I found my way off the board on the second link lol Quote
wrux Posted June 13, 2014 Posted June 13, 2014 Good stuff I've seen in a while: http://tridiv.com/ and http://www.playfuljs.com/a-first-person-engine-in-265-lines/ I did work with ray casting and ray tracing at university & thats pretty good going for 265 lines Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.