Jump to content

Get signed rover speed


Recommended Posts

Evening.

I'm trying to work out how to get the speed of a rover, though signed negative to indicate when it's travelling backwards. Is there an available method to do this that I've missed? I've just spent and hour hunting through the stuff that comes up in the VS inspector for this.vessel., but come up blank so far.

Thanks, as ever :)

Link to comment
Share on other sites

That's going to be hard due to how symmetry works, but I imagine if you could decide on a forward vector for the wheel and have it be uniform across the vessel and over time, then you could just compare the vessel's movement to that vector to determine the signage and apply that to the value you get off the wheelcollider.

Link to comment
Share on other sites

The velocity of the vessel will be a vector, rather than a scalar, making the meaning of "negative direction" sort of meaningless. It's more like "velocity in this 3-D direction."

To get the surface-relative velocity instead of the orbit-relative velocity, use Vessel.GetSrfVelocity().

To get a unit vector pointing in the direction the vessel is pointed, do one of these two things:

roverFrontUnit = Vessel.GetTransform().rotation * V(0,0,1) // Gives a unit vector pointing "up to the nosecone" of a rocket built in the VAB.

roverFrontUnit = Vessel.GetTransform().rotation * V(1,0,0) // Gives a unit vector pointing "ahead to the front" of a vehicle built in the SPH.

Which way is correct depends on which way you built the rover orientation.

(This is from my memory and I might have it wrong which unit vector to start from. It might be the Y axis not the X axis. Please experiment and try).

Once you have such a unit vector, you can dot-product the vector with the surface velocity to get the component of the surface velocity that is aimed forward (positive number) or backward (negative number).

Link to comment
Share on other sites

For future reference, this works perfectly:


//C#
Vector3 roverForward = this.vessel.GetTransform().rotation * new Vector3(0,1,0); //y is forward direction for SPH built craft
Vector3 travelVector = this.vessel.GetSrfVelocity();
float travelDirection = Vector3.Dot(roverForward, travelVector);

I never thought I'd find an actual use for dot products :cool:

Thanks again!

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