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 Professional Discussion / Moving my object up and down

Author
Message
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 3rd May 2011 18:15
Hello everyone I'm having a problem with moving my ship/ aircraft up and down. As in using my ctrl key to move down and my z key to move up . While also using my arrows keys to move fowards , backwards and turning.


as of now this is the code im using or trying to use to do the above.


if Upkey()=1 then move object 1,MySpeed
if Downkey()=1 then move object 1,0-MySpeed
if Leftkey()=1 then A1Y = wrapvalue(A1Y-(MySpeed/3))
if Rightkey()=1 then A1Y = wrapvalue(A1Y+(MySpeed/3))
if keystate(29)=1 then move object down 1,3
if keystate(48)=1 then move object up 1,3
Daygamer
16
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 3rd May 2011 19:07
Hey Xavier,

Is this your whole program? We might need more to detect the problem. But I did notice that your keystate scancode is 48 for move object up. #48 is for the 'b' key. If you wanted to make it the 'z' key it should be 44 like this:



In the future, I would also suggest putting your code in this:


using these: [ code ] [ /code ] (but without spaces)
Just so it's easier to handle. Good luck with your program. Maybe someone brighter than me can help you more

yrotate when you can spin?
God Bless!
Mychal B
15
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 3rd May 2011 22:27
Is this 3d or 2d?
I might be wrong but if it is 3d then the orientation of your object is going to be the direction it moves backwards and forwards when you use move Object. You might wanna try...

shipy# = object position y(1);
shipx# = object position x(1);
shipz# = object position z(1);
if upkey() = 1 then position object 1,shipx#, shipy# + 10, shipz#;
let me know if it helps...im not sure
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd May 2011 23:31
I've only recently found that there's some extra commands in some of the latest DBP upgrades. 'move object up', 'move object down', 'move object left', etc... A lot easier than having to add your own cos and sin functions. The latest DBP 7.6 has them in.

Warning! May contain Nuts!
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 6th May 2011 18:10
This is my code if it lets you open it .. anytime i try to post it it says it has bad language in it and i have no idea wat it is talking about.. Hopefuly you guys can read the attachment
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 6th May 2011 18:13
Here is my ship also jut use a random image for the walls and rem out the fire particles on line 133 so you dont have errors
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 9th May 2011 18:37
Here is the code im trying to use and having trouble with.. Im trying to make my ship move up and down . I can move the ship forwards backwards right and left already but not open and down via using another key


This is one code i tried

Rem control input
if Upkey()=1 then move object 1,myspeed
if Upkey()=1 then move object 1,MySpeed
if Downkey()=1 then move object 1,0-MySpeed
if Leftkey()=1 then A1Y = wrapvalue(A1Y-(MySpeed/3))
if Rightkey()=1 then A1Y = wrapvalue(A1Y+(MySpeed/3))
if Inkey$() ="v" then move object down 1pY# = (1pY# - mydown)
if Inkey$() ="c" then 1pY# = (1pY# - myup)
if scancode() =56 then 1pY# = (1pY# - mydown)


This is the second code

if Leftkey()=1 then 1aY = wrapvalue(1ay-myturn1)
if Rightkey()=1 then 1aY = wrapvalue(1aY+myturn2)
if controlkey()=1 then 1pY# = (1pY# + myup)
if Inkey$() ="v" then 1pY# = (1pY# - mydown)
if Inkey$() ="c" then 1pY# = (1pY# - myup)
if scancode() =56 then 1pY# = (1pY# - mydown)
if Inkey$() =0 then 1pY# = (1pY# - mydown)
if Inkey$() =1 then 1pY# = (1pY# + 5)
if Upkey()=1 then move object 1,myspeed
if Downkey=1 then move object 1,myspeed2




This is the 3rd code that only lets me move right left forwards and backwards with no errors.

if Upkey()=1 then move object 1,MySpeed
if Downkey()=1 then move object 1,0-MySpeed
if Leftkey()=1 then A1Y = wrapvalue(A1Y-(MySpeed/3))
if Rightkey()=1 then A1Y = wrapvalue(A1Y+(MySpeed/3))
if keystate(29)=1 then MOVE OBJECT UP 1, 1
if keystate(44)=1 then MOVE OBJECT DOWN 1, 1
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 10th May 2011 01:58
try not to use the "if" command much better write the code this way:

move object 1,myspeed*(upkey()-downkey())
A1Y=wrapvalue(A1Y+(MySpeed/3)*(leftkey()-writekey()))

and so on.
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 10th May 2011 17:58


gives me an error saying write key does not exist in your program
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 10th May 2011 17:59


gives me an error saying write key does not exist in your program
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th May 2011 18:50
I think he meant "rightkey()"

xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 11th May 2011 17:51
it just doesnt elt me turn right or left when i do it that way had to use
if Leftkey()=1 then A1Y = wrapvalue(A1Y-(MySpeed/3))
if Rightkey()=1 then A1Y = wrapvalue(A1Y+(MySpeed/3))
instead
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 16th May 2011 17:58
does anyone have the code that actually allows me to move my charaacter/ship up and down?

i can move forwards , backwards and turn, but i need the up and down badly if anyone knows
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th May 2011 18:14
Quote: "does anyone have the code that actually allows me to move my charaacter/ship up and down?

i can move forwards , backwards and turn, but i need the up and down badly if anyone knows"

The commands are the ones you yourself posted already:

Are these commands not working?

xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 17th May 2011 18:12


im not moving up and down is their an error in this?
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 17th May 2011 18:19
i also have some gravity in the code but ive remmed some if it out bc without it my game end.

its in this attachment
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th May 2011 18:20
Try this:


The main problem is that you are moving the object up and then down by 10 so it will never go anywhere...

Just check the value of "myspeed". If that is zero then this won't work. You might also be better using a "floating point" variable instead of an integer like this "myspeed#" as it will be more accurate. Also you seem to be using different versions of the same variable but with upper and lower case, this is bad practice.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th May 2011 18:20
Yup, you're moving up 10 and then back down 10 so it's not going anywhere...

Warning! May contain Nuts!
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 17th May 2011 18:32
What im trying to say even if i had it as 10 up and 2 down im not movign anywhere at all besides forwards back and turning .. maybe i dont have my number set high enough
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 17th May 2011 18:34


same problem any other suggestions?
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th May 2011 18:38
Quote: "What im trying to say even if i had it as 10 up and 2 down im not movign anywhere at all besides forwards back and turning .. maybe i dont have my number set high enough "

Might well depend on the size of your object but I'd be surprised if you didn't notice anything.

Try this:


xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 20th May 2011 18:31
this is what i have now i can mvoe up and down slowly but im sure i can fix that but now i cant turn right or left.

Also my camera is not following my ship ive tried using P and A to no prevail.

Any suggestions?

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th May 2011 21:22
You will need to add the SET CAMERA TO FOLLOW inside the do ... loop for it to work properly as it updates each time the function is called.

Warning! May contain Nuts!
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 23rd May 2011 18:01
meh ok now i cant mvoe up anymore my code jsut jacked up my game so now im back to square one trying to move up and down with a letter key so a keystate and its not wokring =(
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 23rd May 2011 18:10
This is what im trying to do now since im jsut frustrated its not working. I want to use my arrow keys to move and i want to use the two mouse buttons to move up and the other to move down dos anyone see what im doing wrong in this code?.


baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 23rd May 2011 18:17
The code I posted should have worked, you seem to be moving the object for no reason after the basic movement control...

Try this slight change:


Do you have any other objects that are visible so you can test whether you are moving up and down? The demo I posted shows a 'ground' object as a reference.

Moving 1000 units seems a lot, what size is your object?

xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 23rd May 2011 18:28
their are little balls in my game and im watching them to see if i mvoe and no my ship did not move up or down.

those lines that u asked or wondering what they were for they came from a post that said for em tot ry using them to mvoe up and down so ive beent rying to use them but nothings worked yet.


also my ship is roughly half the width of my 22 inch flat. idk how many pixels that is tho.

but i tested the code you posted and it did not work =(
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 23rd May 2011 18:32
i did make the up and down different numbers so their not equal before u see that error XP
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 23rd May 2011 18:37
Try this code in a new project just to test:


If that does not work when you press upkey() and downkey() you have some kind of problem with your installation.

xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 24th May 2011 18:15
ok my ship mvoes up and down now but not forwards and backwards and it cant turn right or left...
Heres the code i have now.




xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 24th May 2011 18:17
sorry this is the code i meant to post


baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th May 2011 18:35
OK, well at the moment the only code in your "do" loop is the up and down code.

I see the problem here is fundamental to how a game works.

Anything you put before the 'loop' will only run once so usually we just put our setup code here (loading media etc). Anything you put in the loop will run over and over again until you close the window or hit escape. Space after the loop can be used to put sub-routines and functions in.

Your code for moving forward / backward and turning is all before the loop so will only ever run once before the actual game starts.

Try this:


Maybe you should take a look at some tutorials: http://forum.thegamecreators.com/?m=forum_view&t=115633&b=7

xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 25th May 2011 18:01
its working now but the code for turning has a parameter issue even if i use the wrapvalue code from before it wont turn it jsut doesnt have an error when i load it.
xavier jefferson
15
Years of Service
User Offline
Joined: 11th Apr 2011
Location:
Posted: 25th May 2011 18:04
i also want the camera to folow my ship so like 1st person view so that the camera always sees the entire ship ..

like as if you were playing a racing game or world of warcraft

i need it to view my ship from the back no mater where it goes.

trying some of the help commands atm.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th May 2011 18:09
Quote: "the code for turning has a parameter issue"

What kind of issue?

Quote: "even if i use the wrapvalue code from before it wont turn"

Perhaps you aren't updating the variables? Can I suggest you either post all of your code / project or try starting with some tutorials. You might find some useful information and help here: Newcomers forum

Quote: "it jsut doesnt have an error when i load it."

If you mean you don't get an error but it doesn't work anyway that's because you don't always get an error message when you write the code wrong. Sometimes it looks right when it isn't.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th May 2011 18:11
Quote: "i also want the camera to folow my ship so like 1st person view so that the camera always sees the entire ship .."

That would be third person. First person is when you have a view from inside the ship.

Again, try some tutorials you'll learn a LOT from them. I know I did...

Login to post a reply

Server time is: 2026-07-10 21:41:46
Your offset time is: 2026-07-10 21:41:46