- Home /
Unity4 GetComponent(CharacterMotor) not working
Ok, I'm trying to create a simple script that detects my character's y against a set water level and turns off gravity when <=. I plan on expanding on it in the future, but right now my biggest hangup is just taking control of the built in CharacterMotor in the First Person Controller that comes with Unity. I've done a bit of research and know I'm supposed to be able to pull this in by using GetComponent(CharacterMotor). Only one problem though... where the hell is CharacterMotor?? Mono doesn't list it in the intellitype drop down, I instead see CharacterController, CharacterInfo, and CharacterJoint, but no CharacterMotor. If I forcefully enter this, I get BCE0005: Unknown identifier: 'CharacterMotor'. I see that it exists in Sources/Scripts under the Character Controller folder, and I even see it attached to the prefab I dragged onto my scene...
Here's my code, now admittedly it's BOO script, however I've tried the same thing in JS and I get the exact same problem, nothing can find CharacterMotor:
import UnityEngine
class Swim (MonoBehaviour):
public waterlevel as double
private character as GameObject
def Start ():
character = GameObject.Find("First Person Controller")
chMotor = character.GetComponent(CharacterMotor)
def Update ():
if character.transform.position.y <= waterlevel:
chMotor.Movement.Gravity = 0
else:
chMotor.Movement.Gravity = 20
What am I doing wrong here?
Can you post screenshot evidence that a Character$$anonymous$$otor file is in your project?
I should also note that I tried doing this in a new project too just to see if something may have imported funky in the original, same problem. I also get this on a different computer as well. So I'm pretty sure it's just something I'm not doing right.
Answer by flaviusxvii · Dec 13, 2013 at 09:19 PM
http://unitygems.com/script-interaction-tutorial-getcomponent-boo/
scriptB = GetComponent[of ScriptB]()
I can't imagine why you'd want to use Boo. Not that it isn't a lovely language full of character and joy.. but dang, there just isn't any documentation for it.
I love python, I find the best way to for me to learn anything, languages included, is to dive right in. Thank you so much for this! I'm gonna look it over and see if I can get this to run.
I love python too, but Boo is nothing like it. The syntax is superficially similar, but otherwise it's just missing the "soul" and ease=of-use of python.
That's why I've embedded IronPython in my project.. I can straight-up write stuff like this:
import Chroma
import ComponentUtil
import PyBehaviour
import PyScript
class TestReload(object):
def __init__(self):
self.chroma = Chroma(Color.red)
def Update(self):
self.chroma.shiftHue(Time.deltaTime * 20)
self.chroma.shiftSaturation(Time.deltaTime * 15)
self.gameObject.renderer.material.color = self.chroma.getColor()
def On$$anonymous$$ouseDown(self):
TestReload.selected = self.gameObject
def OnGUI(self):
GUI.Label(Rect(50, 50, 500, 500), self.gameObject.name)
if GUI.Button(Rect(70, 70, 80, 20), "Reset"):
pb = ComponentUtil.findInLineage[PyBehaviour](self.gameObject)
pb.reset()
if GUI.Button(Rect(70, 90, 80, 20), "Clone"):
another = Object.Instantiate(self.gameObject,
self.gameObject.transform.position + Random.onUnitSphere * 3,
Quaternion.identity)
another.name = "stuff %f" % Random.Range(0, 1)
if GUI.Button(Rect(70, 110, 80, 20), "FULL"):
PyScript.fullReset()
def On$$anonymous$$ouseUp(self):
self.gameObject.transform.Rotate(15, 0, 0)
cam = GameObject.FindWithTag("$$anonymous$$ainCamera")
if cam != None:
cam.transform.Rotate(15, 0, 0)
NICE! I'm a newb so I saw boo as a unity version of python. I wasn't aware I could import python directly like that! Got any tutorials on how to best go about doing that? Also, your answer worked!
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Faux Gravity Prolem? #2 2 Answers
Adding multiple colliders to my character controller 1 Answer
How to set gravity for model? 1 Answer
Script Error 1 Answer