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 / Help with movement (banking an object)

Author
Message
TheShogun
13
Years of Service
User Offline
Joined: 3rd Oct 2010
Location: Texas
Posted: 4th Nov 2011 03:39
I'm trying to make an aircraft move. To make it realistic I am rotating the object however, I noticed that the move object commands move the object in a plane relative to the object.

Essentially what I am trying to do is make the ship bank and move in a horizontal direction when a key is pressed (i'm using left and right)
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 4th Nov 2011 04:55
If you can show the code or explain more that would help alot.

TheShogun
13
Years of Service
User Offline
Joined: 3rd Oct 2010
Location: Texas
Posted: 4th Nov 2011 05:08
I somewhat fixed the problem but now I want the object rotation to return to it's default value over time.
do
move object 1, 5
if upkey() = 1 then pitch object up 1, 1
if downkey() = 1 then pitch object down 1, 1
`if leftkey() = 1 then move object 1, 1
`if rightkey() = 1 then zrotate object 1, ARG
if rightkey() = 1 then turn object right 1, 2
if leftkey() = 1 then turn object left 1, 2
`if rightkey() = 1 then zrotate object 1, 45
`if rightkey() = 1 then roll object right 1, 3
`if object angle x (1) > 6 then end
`position camera 1, object position x(1), object position y(1)+20, object position z(1)-50
`Print "ARG" ; ARG
`ARG=ARG+1
if object angle x (1) > 0 then print "help here"
`if rightkey = 0 then
`if upkey = 0 then
`if downkey = 0 then
set camera to follow 1, object position x (1), object position y(1), object position z(1), 0, 50, 5, 20, 1
loop
The code a little messy since I was trying to solve the problem.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 4th Nov 2011 05:34 Edited at: 4th Nov 2011 05:37
turn object right is a command? Lol, I'm not really a 3D person, but I'm assuming the problem is you're not storing the data so it edits it, then just sets it back to normal, but I'm not sure, 2D works differently than 3D

And also use a repeat until loop like this to set it back.



TheShogun
13
Years of Service
User Offline
Joined: 3rd Oct 2010
Location: Texas
Posted: 4th Nov 2011 05:44
I think I know what you mean. Thanks.
TheShogun
13
Years of Service
User Offline
Joined: 3rd Oct 2010
Location: Texas
Posted: 4th Nov 2011 07:28
Hold on.
I set the turn commands to variables, but I can't seem to figure out how to perform two commands when no keys are pressed. I'm trying to modify two variables (Masterasx and Masterasy) in an if statement.

do
rem ***200up, 203left, 205right, 208down*** scan code

move object 1, 5

if scancode() = 0
xrotate object 1, Masterasx
endif
if scancode() = 0
if Masterasx > 1 then Masterasx = Masterasx -1
if Masterasx < 1 then Masterasx = Masterasx +1
endif
if scancode() = 0
yrotate object 1, Masterasy
endif
if scancode () = 0
if Masterasy > 1 then Masterasy = Masterasy -1
if Masterasy < 1 then Masterasy = Masterasy +1
endif
if upkey() = 1 then pitch object up 1, wrapvalue(Masterasx) -1
if downkey() = 1 then pitch object up 1, wrapvalue(Masterasx) +1
if rightkey() = 1 then turn object right 1, wrapvalue(Masterasy) +1
if leftkey() = 1 then turn object right 1, wrapvalue(Masterasy) -1
set camera to follow 1, object position x (1), object position y(1), object position z(1), 0, 50, 5, 20, 1
loop
nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 4th Nov 2011 12:54 Edited at: 4th Nov 2011 12:55
Have you had a look at the DBPro demo on this sort of thing? It may help you. Also, you could set flags to specify whether or not the object was pitched up/down, ie (something like this):

This is just a rough idea, it's not really very useable code. You'd need to add a counter to track by what degree it's been pitched etc.

Also, you should place your code in snippets. "code" in square brackets "[]" then your code then "/code" in square brackets. It makes the threads less cluttered and makes code easier to read

EDIT: Ah, you posted just as I did. In case anybody wonders, the above was in response to the previous posts (I have not read the one just above this yet)

nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 4th Nov 2011 13:21
Quote: "I'm trying to modify two variables (Masterasx and Masterasy) in an if statement."




Is this what you mean?

Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 4th Nov 2011 13:32
My suggestion would be to ditch the 'move object' command and position the object manually using x, y and z values. You can then freely rotate the object however you like without affecting its movement. Here's a small example to show you what I mean:



TheShogun
13
Years of Service
User Offline
Joined: 3rd Oct 2010
Location: Texas
Posted: 4th Nov 2011 15:18
Quote: "position the object manually using x, y and z values"

This is especially what I needed. I see it now (moving the object relative to its current position).
Thanks 'fer the help guys.

Login to post a reply

Server time is: 2024-05-20 06:11:27
Your offset time is: 2024-05-20 06:11:27