Jump to content

Accessing the WheelCollider of a rover wheel


Recommended Posts

First, look at this image:

XHZoV2G.png

I need to access the WheelCollider of a rover wheel. In the config file there is a field named "wheelColliderName", and the value is "wheelCollider" for all stock wheels, but i tried to use transform.Find() to search for the GameObject named "wheelCollider" and i found nothing (and the problem was not my plugin, it worked with "Hello World"). But i am not even sure in what GameObject (of the image) my script is attached, so i am probably doing something wrong. Does anyone know how to access the WheelCollider?

Link to comment
Share on other sites

There are a couple ways. It looks like PartTools rearranges the transforms a little, so here's something of a roadmap of the ingame hierarchy:


[LOG 18:24:33.499] Transform: roverWheel1
[LOG 18:24:33.499] ---> Transform: model
[LOG 18:24:33.500] ------> Transform: roverWheelBig
[LOG 18:24:33.501] ---------> Transform: base
[LOG 18:24:33.501] ------------> Transform: susp1-2
[LOG 18:24:33.502] ------------> Transform: susp2-2
[LOG 18:24:33.502] ------------> Transform: susp3-2
[LOG 18:24:33.503] ---------> Transform: suspensionNeutralPoint
[LOG 18:24:33.504] ------------> Transform: steering
[LOG 18:24:33.504] ---------------> Transform: wheelCollider
[LOG 18:24:33.505] ---------> Transform: suspensionTraverse
[LOG 18:24:33.506] ------------> Transform: bracket
[LOG 18:24:33.506] ------------> Transform: susp1-1
[LOG 18:24:33.507] ---------------> Transform: susp3-1
[LOG 18:24:33.508] ------------> Transform: susp2-1
[LOG 18:24:33.508] ------------> Transform: trackSteering
[LOG 18:24:33.509] ---------------> Transform: bustedwheel
[LOG 18:24:33.510] ------------------> Transform: bustedwheel
[LOG 18:24:33.510] ------------------> Transform: collisionEnhancer
[LOG 18:24:33.511] ------------------> Transform: Object01
[LOG 18:24:33.512] ---------------> Transform: wheelMount
[LOG 18:24:33.513] ------------------> Transform: wheel
[LOG 18:24:33.513] ---------------------> Transform: collisionEnhancer


[LOG 18:24:33.441] roverWheel1 has components:
[LOG 18:24:33.441] ...c: UnityEngine.Transform
[LOG 18:24:33.442] ...c: Part
[LOG 18:24:33.443] ...c: ModuleWheel
[LOG 18:24:33.443] ...c: FXModuleLookAtConstraint
[LOG 18:24:33.444] ...c: FXModuleConstrainPosition
[LOG 18:24:33.445] ...c: UnityEngine.AudioSource
[LOG 18:24:33.445] ...c: UnityEngine.Rigidbody
[LOG 18:24:33.446] ...c: CollisionEnhancer
[LOG 18:24:33.446] ...c: PartBuoyancy
[LOG 18:24:33.447] --->model has components:
[LOG 18:24:33.448] ......c: UnityEngine.Transform
[LOG 18:24:33.448] ------>roverWheelBig has components:
[LOG 18:24:33.449] .........c: UnityEngine.Transform
[LOG 18:24:33.450] --------->base has components:
[LOG 18:24:33.450] ............c: UnityEngine.Transform
[LOG 18:24:33.451] ............c: UnityEngine.BoxCollider
[LOG 18:24:33.452] ............c: UnityEngine.MeshFilter
[LOG 18:24:33.452] ............c: UnityEngine.MeshRenderer
[LOG 18:24:33.453] ------------>susp1-2 has components:
[LOG 18:24:33.454] ...............c: UnityEngine.Transform
[LOG 18:24:33.454] ...............c: UnityEngine.MeshFilter
[LOG 18:24:33.455] ...............c: UnityEngine.MeshRenderer
[LOG 18:24:33.456] ------------>susp2-2 has components:
[LOG 18:24:33.456] ...............c: UnityEngine.Transform
[LOG 18:24:33.457] ...............c: UnityEngine.MeshFilter
[LOG 18:24:33.458] ...............c: UnityEngine.MeshRenderer
[LOG 18:24:33.458] ------------>susp3-2 has components:
[LOG 18:24:33.459] ...............c: UnityEngine.Transform
[LOG 18:24:33.460] ...............c: UnityEngine.MeshFilter
[LOG 18:24:33.460] ...............c: UnityEngine.MeshRenderer
[LOG 18:24:33.461] --------->suspensionNeutralPoint has components:
[LOG 18:24:33.462] ............c: UnityEngine.Transform
[LOG 18:24:33.462] ------------>steering has components:
[LOG 18:24:33.463] ...............c: UnityEngine.Transform
[LOG 18:24:33.464] --------------->wheelCollider has components:
[LOG 18:24:33.464] ..................c: UnityEngine.Transform
[LOG 18:24:33.465] ..................c: UnityEngine.WheelCollider
[LOG 18:24:33.466] --------->suspensionTraverse has components:
[LOG 18:24:33.467] ............c: UnityEngine.Transform
[LOG 18:24:33.467] ------------>bracket has components:
[LOG 18:24:33.468] ...............c: UnityEngine.Transform
[LOG 18:24:33.469] ...............c: UnityEngine.BoxCollider
[LOG 18:24:33.469] ...............c: UnityEngine.MeshFilter
[LOG 18:24:33.470] ...............c: UnityEngine.MeshRenderer
[LOG 18:24:33.471] ------------>susp1-1 has components:
[LOG 18:24:33.471] ...............c: UnityEngine.Transform
[LOG 18:24:33.472] ...............c: UnityEngine.MeshFilter
[LOG 18:24:33.473] ...............c: UnityEngine.MeshRenderer
[LOG 18:24:33.473] --------------->susp3-1 has components:
[LOG 18:24:33.474] ..................c: UnityEngine.Transform
[LOG 18:24:33.475] ..................c: UnityEngine.MeshFilter
[LOG 18:24:33.475] ..................c: UnityEngine.MeshRenderer
[LOG 18:24:33.476] ------------>susp2-1 has components:
[LOG 18:24:33.477] ...............c: UnityEngine.Transform
[LOG 18:24:33.478] ...............c: UnityEngine.MeshFilter
[LOG 18:24:33.478] ...............c: UnityEngine.MeshRenderer
[LOG 18:24:33.479] ------------>trackSteering has components:
[LOG 18:24:33.480] ...............c: UnityEngine.Transform
[LOG 18:24:33.481] --------------->bustedwheel has components:
[LOG 18:24:33.481] ..................c: UnityEngine.Transform
[LOG 18:24:33.482] ------------------>bustedwheel has components:
[LOG 18:24:33.483] .....................c: UnityEngine.Transform
[LOG 18:24:33.483] .....................c: UnityEngine.MeshFilter
[LOG 18:24:33.484] .....................c: UnityEngine.MeshRenderer
[LOG 18:24:33.485] ------------------>collisionEnhancer has components:
[LOG 18:24:33.485] .....................c: UnityEngine.Transform
[LOG 18:24:33.486] .....................c: UnityEngine.SphereCollider
[LOG 18:24:33.487] ------------------>Object01 has components:
[LOG 18:24:33.488] .....................c: UnityEngine.Transform
[LOG 18:24:33.488] .....................c: UnityEngine.MeshFilter
[LOG 18:24:33.489] .....................c: UnityEngine.MeshRenderer
[LOG 18:24:33.490] --------------->wheelMount has components:
[LOG 18:24:33.490] ..................c: UnityEngine.Transform
[LOG 18:24:33.491] ..................c: UnityEngine.MeshFilter
[LOG 18:24:33.492] ..................c: UnityEngine.MeshRenderer
[LOG 18:24:33.492] ------------------>wheel has components:
[LOG 18:24:33.493] .....................c: UnityEngine.Transform
[LOG 18:24:33.494] .....................c: UnityEngine.MeshFilter
[LOG 18:24:33.495] .....................c: UnityEngine.MeshRenderer
[LOG 18:24:33.495] --------------------->collisionEnhancer has components:
[LOG 18:24:33.496] ........................c: UnityEngine.Transform
[LOG 18:24:33.497] ........................c: UnityEngine.SphereCollider

You can see a transform named "model" in there where the Unity hierarchy got moved. KSP accesses this portion of the GameObject in a different way; you might've come across Part.FindModel* functions. Use those to find stuff you're looking for that's underneath the model section of the tree. So if you want to find a transform named "wheelCollider" you'll be wanting

myPart.FindModelTransform("wheelCollider")

You can use the base transform to do it, but for that you apparently need the whole path:

transform.Find("model/roverWheelBig/suspensionNeutralPoint/steering/wheelCollider");

You can also look for the component(s) directly, being careful around cases where more than one might exist of course:

var wc = part.FindModelComponent<WheelCollider>();
var wc2 = part.gameObject.GetComponentInChildren<WheelCollider>();

Link to comment
Share on other sites

xEvilReeperx just pointed me in this direction (thank you again!). I've been working on tweakable suspension over the last couple of days myself! Still a bit flaky.. Will hold off if you've got something working, and very interested to see what a fully workable solution looks like :)

Link to comment
Share on other sites

xEvilReeperx just pointed me in this direction (thank you again!). I've been working on tweakable suspension over the last couple of days myself! Still a bit flaky.. Will hold off if you've got something working, and very interested to see what a fully workable solution looks like :)

I am not the creator of TweakableWheels, OrbitusII is.

Link to comment
Share on other sites

I've figured out how to modify settings of the wheelcollider. Very new to writing plugins, so it's rough but functional.

Source here:

https://github.com/Lo-FiOrbitalScience/KSPWheelPack?files=1

It doesn't work very well in realtime, though. Seems to modify the value, then ksp will all of a sudden realise it's changed a few minutes later! Still can't figure that out. Be interested to see what you can come up with, give me a shout if I can help at all.

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