Jump to content

Vector for straight up?


Recommended Posts

So I am using

this.rigidbody.AddForce()

I would like to have a force applied directly up (regardless of ship orientation) but the problem is I can't seem to get the right vector.

I tried Vector3.up but that just created a force north rather than up. Like this

So naturally I tried the others, eg. .down, .left, .right etc. but they did not seem to be in 90 deg rotations.

for example Vector3(0,0,1) was at a 45 deg angle.

The only vector that seems to point straight up is (-1.46,0,1) but I don't want to use a combination of value I just want 2 zero values and then a positive value (eg. 0,0,1) as using a combination creates oscillations.

This has probably been quite difficult to follow and I can give more info if needed but hopefully someone can help. :)

Link to comment
Share on other sites

You're forgetting that you need to apply the force in world coordinates, not in local coordinates. While Vector.up is correct in local coordinates, you want the vector that represent up at the ship's coordinates. Else how can the game know "where" is up?

Basically, what you need is a vector that points away from the center of the CelestialBody. What you want is (vessel.transform.position - vessel.mainBody.position). I believe vessel.upAxis and FlightGlobals.getUpAxis(vessel.mainBody, vessel.transform.position) are exactly the same as well.

Link to comment
Share on other sites

You're forgetting that you need to apply the force in world coordinates, not in local coordinates. While Vector.up is correct in local coordinates, you want the vector that represent up at the ship's coordinates. Else how can the game know "where" is up?

Basically, what you need is a vector that points away from the center of the CelestialBody. What you want is (vessel.transform.position - vessel.mainBody.position). I believe vessel.upAxis and FlightGlobals.getUpAxis(vessel.mainBody, vessel.transform.position) are exactly the same as well.

Thanks so much, this seems to do just what I want it to :)

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...