Jump to content

Vector3d for position


Recommended Posts

Hi,

I wanted to get my current altitude by using the GetAltitude member function of the CelestialBody class. The argument for the funtion is a 3d vector. So how does 3d vectors are being used to express your position or any position on a planet.

PS:Please dont tell me that i can use functions that returns the double value for the altitude, I know i can and it is not suitable for what i am doing right now.

Thanks!

Link to comment
Share on other sites

Vectors start in some arbitrary point in space, which in addition jumps randomly as the game goes. That's called 'floating origin' :rolleyes:. So, to get vessel's position relative to planet's center, you

  • get vessel's global position,
  • get global position of current celestial body (refer to Vessel and CelestialBody classes implementations),
  • and subtract.
  • ah, uh, and do not store any of that 'global positions' between frames! Next jump of 'floating origin' will render them invalid! Only subtraction result will make sense then.

Link to comment
Share on other sites

Vectors start in some arbitrary point in space, which in addition jumps randomly as the game goes. That's called 'floating origin' :rolleyes:. So, to get vessel's position relative to planet's center, you
  • get vessel's global position,
  • get global position of current celestial body (refer to Vessel and CelestialBody classes implementations),
  • and subtract.
  • ah, uh, and do not store any of that 'global positions' between frames! Next jump of 'floating origin' will render them invalid! Only subtraction result will make sense then.

What if I want to "predict" the altitude that is on the way of my heading? I tried adding my velocity vector to my global position vector but I dont know if it is working or not? I think Mathematically it is correct? or is it not?

Link to comment
Share on other sites

What if I want to "predict" the altitude that is on the way of my heading? I tried adding my velocity vector to my global position vector but I dont know if it is working or not? I think Mathematically it is correct? or is it not?

That's almost correct, but your velocity vector is in units/second, so what you did would give you your predicted altitude a second from "now", and a lot can happen in a second.

If you want to get your altitude at the next frame, you can do GetAltitude(position + (velocity * Time.deltaTime)).

Mind though, that this assumes no forces will act on your vessel, which is ok on low velocities, but will be pretty inaccurate in orbit, for instance. To get a more precise prediction of your position at any point in time, use the Orbit methods, like Orbit.getPositionAtUT(Planetarium.GetUniversalTime() + someTimeFromNow);

Cheers

Link to comment
Share on other sites

That's almost correct, but your velocity vector is in units/second, so what you did would give you your predicted altitude a second from "now", and a lot can happen in a second.

If you want to get your altitude at the next frame, you can do GetAltitude(position + (velocity * Time.deltaTime)).

Mind though, that this assumes no forces will act on your vessel, which is ok on low velocities, but will be pretty inaccurate in orbit, for instance. To get a more precise prediction of your position at any point in time, use the Orbit methods, like Orbit.getPositionAtUT(Planetarium.GetUniversalTime() + someTimeFromNow);

Cheers

Thanks a lot Harvester :).

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...