Hello,
I am trying to expose the force value in the WheelHit struct in the Car Tutorial and print it to the console.
I made a gameObject called infoGUI, with a JS Script called infoGUI.js.
When I run the code, I get this error:
MissingMethodException: Method not found: ‘UnityEngine.WheelCollider.GetGroundHit’.
Here is the code:
private var frontWheelLeft;
private var fwlInfo : WheelHit;
function Awake () {
guiText.material.color = Color.white;
}
function Start() {
frontWheelLeft = GameObject.Find("DiscBrakeFL Collider").GetComponent(WheelCollider);
}
function FixedUpdate () {
frontWheelLeft.GetGroundHit(fwlInfo);
print(fwlInfo.force);
}
Thanks!
EDIT: I should note that printing out something like frontWheelLeft.radius works just fine, which is why I don’t know the reason for GetGroundHit not working.
What is the type of frontWheelLeft ?
It’s a WheelCollider. I guess the code would be more efficient if I had declared the type in the beginning instead of letting JavaScript doing it dynamically on Start. Nevertheless, it should work like this because as I mentioned I was able to access some of the WheelCollider’s properties like the radius, but not the GetGroundHit function.
Thanks!
Declare the type of the frontWheelLeft.
That should solve the problem.
private var frontWheelLeft : WheelCollider;
private var fwlInfo : WheelHit;
function Awake () {
guiText.material.color = Color.white;
}
function Start() {
frontWheelLeft = GameObject.Find("DiscBrakeFL Collider").GetComponent(WheelCollider);
}
function FixedUpdate ()
{
frontWheelLeft.GetGroundHit(fwlInfo);
print(fwlInfo.force);
}
This should work.
It did work! Thank you so much.
Would you mind giving me a bit of theory behind the reason why it didn’t work before? How come I was able to access radius and not GetGroundHit?
I guess letting JS dynamically assign types should be avoided whenever possible, even though it seems it wasn’t doing so here.