Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Problem; cube wont move

Author
Message
Mizipzor
20
Years of Service
User Offline
Joined: 24th May 2004
Location: Sweden
Posted: 31st May 2004 00:37
I decided to try add friction to my game. The cube is supposed to move but doesnt. It works in the way that i take the speed and ad the acceleration, takes the result and multiplie it with the friction value. I dont know where to error lies but this is the entire move subroutine:



The entire source is attached as well if you want to try it out yourself.

Thanks in advance
Mizi

Dreaming of creating a highly advanced AI mind
Mizipzor
20
Years of Service
User Offline
Joined: 24th May 2004
Location: Sweden
Posted: 31st May 2004 00:45
Hehe ok... Im silly but i figured it out, i simply forgot to add the # behind the friction variable name.

However, another problem arose. Once the cube starts to move it doesnt stop... i got no friction whatsoever! I dont know what Ive missed this time. Please help out.

Anyways... heres the new source with the acceleration and friction i use:



Thanks in advance

Dreaming of creating a highly advanced AI mind
GameKit
21
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 31st May 2004 08:44 Edited at: 31st May 2004 08:47
I only skimmed over your code, but this was the only thing I noticed...

rem sort out movement and check for falloff
if upkey()=1 or downkey()=1
if upkey()=1 then speed#=(speed#+acc#)*friction#
if downkey()=1 then speed#=(speed#-acc#)*friction#
else speed#=speed#*friction
endif
endif

Add the "#" after friction in this line of code also... Right now you are telling the program to set speed# to 0...

[edit]
oh, and also move that code down a line so it reads...

if upkey()=1 or downkey()=1
....
if upkey()=1 then speed#=(speed#+acc#)*friction#
if downkey()=1 then speed#=(speed#-acc#)*friction#
endif
else speed#=speed#*friction#
endif

Well... I hope I helped...

Previously known as "Game_Creator".
The question is, why am I talking to myself? ...... And more importantly, why am I waiting for a reply?
Mizipzor
20
Years of Service
User Offline
Joined: 24th May 2004
Location: Sweden
Posted: 31st May 2004 09:33 Edited at: 31st May 2004 09:34
Thanks... the # is added now but the cube behave a bit strange. Once you press the upkey it starts moving forward at a certain speed. It doesnt slow down to a halt if you realese the upkey, as intended by the friction. And you cant go faster by holding down to upkey, as intended by the acceleration value.

Heres the code as it is now, run it yourself and youll see what i mean.



Dreaming of creating a highly advanced AI mind
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 31st May 2004 10:46
Just needed to move one line out of and if-endif, works now


Mizipzor
20
Years of Service
User Offline
Joined: 24th May 2004
Location: Sweden
Posted: 31st May 2004 10:58 Edited at: 31st May 2004 11:00
Thanks for the help guys.

Thats right if i dont move it there it isnt tested if not the upkey or downkey is pressed... in which case its quite useless i found and fixed another bug as well! As the code is now, as you suggest, you can speed up and use the friction to glide of the matrix... not good.



Well... now on to the next problem . Now when friction and acceleration is implented i thought it would be good the have a maximum speed allowed. But for some reason it wont go all the way up to the max speed. I dont know why, i only test for the mexspeed once and do not change the value.

*Again* heres the entire source... *sigh* lol



Added so that it prints the speed and stuff as well

[edit]
btw, is there any way to declear a max value of decimals printed in the print command? The 15th decimal in the speed value isnt that interesting just clutters up...

thanks again

Dreaming of creating a highly advanced AI mind
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 31st May 2004 11:17
It won't get to the max speed because of friction the friction is working even when you are pressing up or down, this can be changed, but i preferred it the other way, so i just remmed out the lines i changed incase you want them back. I also sorted the debugging code so it only shows a couple of decimal points.


Mizipzor
20
Years of Service
User Offline
Joined: 24th May 2004
Location: Sweden
Posted: 31st May 2004 11:29 Edited at: 31st May 2004 11:30
Thanks again.

Anyways, im thinking of rewriting the entire thing to be more like the binary moon hovercraft tutorial game. I need to split "speed" into "xspeed" and "zspeed" in order to have the yspeed and get gravity and jumping working correctly.

Or do you have any ideas how this could be done?

I made a reeeally lame attempt at gravity, heres what i got:



I take the players Y position and deduct the gravity value, if its below ground height i simply place it at ground height. The problem is i dont get those cool jumps when running of cliffs (those were my goal, theyre cool ). Another problem, the cube is half burrowed again, if i add 5 (half the cube) to the Y value when positioning as i used to the cube fly of into the skies!

Ill take that as a failure hehe

Dreaming of creating a highly advanced AI mind

Login to post a reply

Server time is: 2024-09-22 11:21:40
Your offset time is: 2024-09-22 11:21:40