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.

DarkBASIC Discussion / Problem moving objects

Author
Message
Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 25th Jul 2004 09:17
Ok, I was wondering how to move a cube exactly one square at a time, I know this sounds stupid, but every way I try works, but when you move it in a different direction, both of them dont work. I just dont know whats wrong.

This is how I've got it set, you'll probably suggest something I've already tried, but if you've done this exact thing before in all directions, without it messing up, well, I hail you!



Im watching you...
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 25th Jul 2004 17:25
do
if upkey()
inc objecty
endif
if downkey()
dec objecty
endif
if leftkey()
dec objectx
endif
if rightkey()
inc objectx
endif
position object objnum,objectx,objecty,0
loop

you will have to chose your own x and y positions (or switch to x/z coordinates) for whatever you are trying to do, just increase the positions by the size of the cube (this assumes a 1 unit square cube), cheers.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster.
Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 26th Jul 2004 06:16
yeah, tried that almost exact thing, oh well, I 'll figure it out, thanks anyway

Im watching you...
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 26th Jul 2004 06:37
you might have tried "that almost exact thing" but you didn`t try it correctly or it would have worked, whats the point in posting for help and then ignoring replies?, you obviously didnt try it cos it works just fine with a little extra supporting code :eg

sync on:sync rate 20
make object cube 1,1
objecty=0
objectx=0
position camera 0,0,-20
point camera 0,0,0
do
if upkey()
inc objecty
endif
if downkey()
dec objecty
endif
if leftkey()
dec objectx
endif
if rightkey()
inc objectx
endif
position object 1,objectx,objecty,0
sync
loop

you might at least make an effort when people try to help rather than waiting for it to be served on a platter for you, then people complain that us oldies don`t want to help any more

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster.
Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 26th Jul 2004 07:43
I tried it, with my code and it did'nt work, its not my fault, I was just saying I tried something alot like that, but it didnt work, that does'nt mean I didnt take your help into account.

Im watching you...
Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 26th Jul 2004 07:47
And another thing, why do you "oldies" always assume that your way is right? Anyway it works sort of, but it moves way to fast, so you cant move it to the square you want the cube to be.

Im watching you...
Balid
21
Years of Service
User Offline
Joined: 21st Nov 2003
Location: MI, USA
Posted: 26th Jul 2004 11:43 Edited at: 26th Jul 2004 11:44
AlienMan,

Try this version of the technique:

That should move the object only once everytime you press the upkey.

Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 27th Jul 2004 02:13
For some reason it does'nt work, I've never heard of "upkeydown()", do I need to initialize an array, or a function, or something like that?

Im watching you...
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 27th Jul 2004 02:59 Edited at: 27th Jul 2004 03:01
Quote: "And another thing, why do you "oldies" always assume that your way is right?"


er! cos it works? , the speed isn`t an issue anyway, you can slow it down any number of ways if it is too fast for you, just stick wait 500 at the end of the loop and it will only move every half a second, or use a keydown flag like Balid suggested or use the timer to only allow keypresses to register after 1/2 a second or so, or maybe your code will end up so large you will be wanting to move it faster by the time you have finished,, any number of ways will do the job, just pick a method and use that.

Mentor.

ps: Balid said upkeydown, not upkeydown(), it`s just a variable he uses as a flag to check for the key still being down, only gets reset to allow a keypress to be read when the key has been released

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster.
Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 27th Jul 2004 03:01
well, thanx

Im watching you...
Balid
21
Years of Service
User Offline
Joined: 21st Nov 2003
Location: MI, USA
Posted: 27th Jul 2004 12:54
AlienMan,

Can we see what your code looks like now? Because with the above code using the 'keydown flag' the cube should move one unit each time you press an arrow key. But it will only move in the X and Y plain not the Z (or left/right and up/down, not away/toward you)

Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 28th Jul 2004 00:33
I fixed it, It only works i a function, but thanx anyway

Im watching you...

Login to post a reply

Server time is: 2025-05-24 21:56:27
Your offset time is: 2025-05-24 21:56:27