ââRigidbodyâ does not contain a definition for âvelocityâââŚ
and no matter how I try to access the velocity of the rigidbody it wonât recognize that command, even though it does exist in the Unity official scripting api.
What am I doing wrong?
Looks like youâve made your own script named âRigidbodyâ. Thatâll cause the compiler to think that âRigidbodyâ is your script rather than the built-in Rigidbody.
Strange, I donât remember having a class named Rigidbody, I should mention that this is âextendingâ the tank game tutorial, this is why I could be a little clueless.
Oh, I just noticed I could add UnityEngine.Rigidbody in order to call the built-in Rigidbody,this part compiles now, thanks!
No, you have to use GetComponent in order to get a specific component, since the properties are deprecated nowadays (or have already been removed in recent versions - not quite sure). Once you have an instance of the component type, you can simply access the exposed members.
//Given that 'rb' is already of type Rigidbody:
... = rb.velocity;
// and
... = rb.GetComponent<Rigidbody>().velocity;
// are identical except for a little more overhead in the latter version
That is, you donât need to use GetComponent again as your parameter for the Speedbost method is already of type Rigidbody.
There are several situations in which youâll be forced to use the fully-qualified name.
The one youâve encountered pretty much hints to what @Baste has pointed out. Iâd try to resolve the issue.
Thanks for the information! yeah, @Baste was right and I resolved the issue by using GetComponent<UnityEngine.Rigidbody>().velocity instead.
Now plenty of other errors occurred that werenât here before, but I doubt that has to do with this script. I think Iâll just abandon this all togetherâŚ
Iâd say itâs party resolved.
If youâre not getting errors about using Rigidbody as a type but instead it only throws errors when youâre trying to access the expected members, then thereâs something wrong.
It basically means it knows a type called Rigidbody, but its declaration does not provide the member youâre trying to access. There must be a type in the scope that has a precedence to UnityEngine.Rigidbody unless your IDE does not complain about type-name abiguities.
In regards to the new warnings and errors, check the GameObject named âTankâ and the TankManager component.
There should be some fields which have lost their references to actual instances of the specific types.
The error may be resolved once youâve set the references properly.