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 / vectors and spaceships

Author
Message
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 26th Nov 2013 18:12
I have my spaceship working just the way I want it to, but for one thing. I want it to go up and down. Yes I know about move up and down. this is space and I need when you push the thruster up, you keep moving in that dri, until you use the down thruster. to stop you or to move down. I thing vectors are the way to go.
I have never used vec. before. I been reading on them and have some what a how they work. I just don't know have to use then on DBP.
All I need is how to use them to make my ship go up and down to the pos. of the ship.
If some one can enlighten me I would be so happy.
Thank you
renny

Life is not fair, so deal with it.
http://www.gusworks.com/
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 26th Nov 2013 18:38 Edited at: 26th Nov 2013 18:50
The problem here is it's such a massive field to get into. A vector isn't nothing special, it's just another way of representing a quantity with a direction.

posVecX# = 10
posVecY# = 10
posVecZ# = 10

Is exactly the same as:

set vector3 posVec, 10, 10, 10

The problem is when you start explain how to use them because then you have to introduce other things like trig and matrices especially it we're talking about transformations. The easiest way to get direction of an object is from the inverse of a rotation matrix. So it's all about what you want really. Do you want to know the ins and outs of 3d math which covers all of these or only wants necessary to achieve what you want in the quickest amount of time!

If it's the ins and out's I suggest reading FlipCodes explanations: 3D Geometry Primer: Chapter 1 - Issue 01 - Introduction To Vectors

Just note: Most vector tutorials will talk about vector magnitude. In terms of DPB vectors this won't be that useful unless you include this yourself.

What your aiming for is:

1. Get the Direction Vectors (Up/Right/Look or forward) of your ship from it's angle
2. Scale those vectors by the speed you want to move at
3. Add the scaled vectors to the position of your ship

This will move the ship in the way you want it to.

"Get in the Van!" - Van B
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 27th Nov 2013 00:33 Edited at: 27th Nov 2013 00:34
I'm confused when you say 'thruster'....
Are you talking about the angle of the ship or the speed?

Have you tried PITCH OBJECT UP/PITCH OBJECT DOWN?

D.D.
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 27th Nov 2013 15:41
speed and direction

Life is not fair, so deal with it.
http://www.gusworks.com/
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 27th Nov 2013 20:00 Edited at: 27th Nov 2013 20:06
OK this is the code I came up with, it works half ass.
I think I am going to have to hunt EZ-rotation download it and use that.
I rotate in a wabber type dir.






Vectors are a pain in the ass to learn, but they can be nice to use.
renny

Life is not fair, so deal with it.
http://www.gusworks.com/
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 27th Nov 2013 20:27 Edited at: 27th Nov 2013 20:45
HOLD ON AN EPIC MINUTE!

Is this for 2D or 3D movement because if it's 2D this thing just go a hell of a lot easier with very simple trig or vector2 maths?

(If I know which then I can best help you with your code)

"Get in the Van!" - Van B
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 27th Nov 2013 20:44
Vectors aren't really that complex and the best way to understand them is to rewrite them then you can see what they actually do!

For example: Lets take this code you wrote:

Quote: "
set vector3 thrust, x#, y#, z#
scale vector3 thrust, thrust, 1.1
add vector3 movement, thrust, movement
"


Let's write this if you weren't using vectors:

// set our thrust variable
thrustX# = x#
thrustY# = y#
thrustZ# = z#

Let's stop rigth here! What we have there is a vector or exactly what a vector represents in this case a vector3 because it has 3 quanities XYZ. Remember, vectors are ANOTHER way of representing a quanity but can be used in an way you want (though there is important vector based math but you don't have to get into the serious stuff when your learning them from the start). Let's continue:

// scale our thrust
thrustX# = thrustX# * 1.1
thrustY# = thrustY# * 1.1
thrustZ# = thrustZ# * 1.1

// and lastly add to out movement vector (variables XYZ)
movementX# = movementX# + thrustX#
movementY# = movementY# + thrustY#
movementZ# = movementZ# + thrustZ#

So you can see, all vectors do is simpilify what would be represents in many more lines of code. So when you learn vectors just try to look at whats going on inside, treat them as if they were a function to a maths calculation hidden under the hood!

"Get in the Van!" - Van B
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 27th Nov 2013 22:43
This is 3D that is why the vectors are3.
the thrust works fine it is the rotate that is not just right.
but I got that fixed <I think> I am moving all over the place.
up down forward and backward. So far no problem. Let say I am moving north, I can rotate 90 deg. to the laft and I am still going north.
That is just what i wanted
Thank all of you for your help
renny

Life is not fair, so deal with it.
http://www.gusworks.com/
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th Nov 2013 01:03 Edited at: 28th Nov 2013 01:06
Quote: "This is 3D that is why the vectors are3."


Not entirely true hence why you have vectors 2-4 and sometimes beyond! Vector3 is only necessary because it's has 3 component we need to fill.

Taking a look at your code you rotate the the XYZ component at the same angle when you only want to rotate one! Also, your method of moving forward isn't entirely correct. This is were the math gets alittle difficult and isn't exactly to do with vectors. To find the direction vectors of our object based of it's angle you either have to use a matrix or trig (if we're using a math method) there are a number of cheat ways, for example:

To get the look/forward vector the cheat way you can do this:


Or...


Using trig:


The matrix method is alittle complex so won't get into that yet (but it's the quickest and easiest if you understand how a matrix works)

Using the vector to actually move our object:


Now this is only for forward movement, for up movement you need to scale the up vector, for right movement you need to scale the right vector. If you google direction vectors and trig for them and etc... you can find all the answers you need. For the cheaty methods, just change the just add up or right to the ends of the move object commands for the up and right vectors, and if limbs just put a 1 in the X, Y or Z component for each vector(X=right,Y=up,Z=look)

"Get in the Van!" - Van B
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 28th Nov 2013 17:09
Yes, you are right, after playing with it for a while I found a lot of small problems with the code. So back to work. I will try what you put up there. I am going to try this too.:

Quote: "
Vectors aren't really that complex and the best way to understand them is to rewrite them then you can see what they actually do!

For example: Lets take this code you wrote:

Quote: "
set vector3 thrust, x#, y#, z#
scale vector3 thrust, thrust, 1.1
add vector3 movement, thrust, movement
"

Let's write this if you weren't using vectors:

// set our thrust variable
thrustX# = x#
thrustY# = y#
thrustZ# = z#

Let's stop rigth here! What we have there is a vector or exactly what a vector represents in this case a vector3 because it has 3 quanities XYZ. Remember, vectors are ANOTHER way of representing a quanity but can be used in an way you want (though there is important vector based math but you don't have to get into the serious stuff when your learning them from the start). Let's continue:

// scale our thrust
thrustX# = thrustX# * 1.1
thrustY# = thrustY# * 1.1
thrustZ# = thrustZ# * 1.1

// and lastly add to out movement vector (variables XYZ)
movementX# = movementX# + thrustX#
movementY# = movementY# + thrustY#
movementZ# = movementZ# + thrustZ#

So you can see, all vectors do is simpilify what would be represents in many more lines of code. So when you learn vectors just try to look at whats going on inside, treat them as if they were a function to a maths calculation hidden under the hood!
"


See how that works. I will be back to let you know how things are going. If I get some good working code I will put it up here.
thanks
renny

Life is not fair, so deal with it.
http://www.gusworks.com/
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 28th Nov 2013 22:56
It still not working like I want it to, but much better that it was 6 hours ago. it is coming a long good, hope to have it done soon.
renny

Life is not fair, so deal with it.
http://www.gusworks.com/
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 29th Nov 2013 00:30
See I don't just want to give you the answer, I want you to experiment and play with them to get them working and good to here your still going at it. If you do get stuck though post away and I'm here to help (aswell as others)

"Get in the Van!" - Van B
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 29th Nov 2013 16:09
Thanks

Life is not fair, so deal with it.
http://www.gusworks.com/
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2014 23:34
Go and read my tutorial about 3D Vector math that I wrote for the DBPro community back in 2004. It is called "Vectors Don't Bite" or something like that. Do a search on the forums for it.

Philip

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
sadsack
21
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 20th Jan 2014 22:01
Philip
very nice

Life is not fair, so deal with it.
http://www.gusworks.com/

Login to post a reply

Server time is: 2025-05-15 14:09:57
Your offset time is: 2025-05-15 14:09:57