hello,
i do have a error but i dont know wath it means, can you tell me?
here is the error:
thx
hello,
i do have a error but i dont know wath it means, can you tell me?
here is the error:
thx
No body know?
You are trying to use null pointer object on line #7 of our script Control.js
oke, and wath means dath?
here is my code:
var speed = 3.0;
var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
GameObject.Find("Player(Clone)").transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = GameObject.Find("Player(Clone)").transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)
/*
function OnGUI() {
if(GUI.Button(new Rect(20,100,50,50),"up"))
{
GameObject.Find("Player(Clone)").transform.position = new Vector3(0,5,0);
}
}
*/
but the code on line 7 is work
GameObject.Find(“Player(Clone)”) is returning null.
That’s the most inefficient way I can think of to do that, by the way. Calling that every Update is going to be a “huge” drain on your resources.
Try using
var player : Transform;
and dragging your player object to that instead. Much, much better in terms of readability and speed.
If you must use find you can find it in the Start function.
the results are: no error and no moving.
if i undo that then are the results: an error and moving
conclusion it doent work, wath can i do to make it working
no body?
Your reference to the player’s transform is incorrect or its speed is zero.
The answers provided so far pretty much answer your original question. For whatever reason your code cannot find an object called “Player(Clone)”.
Also, the principal point Vicenti was making about using GameObject.Find still stands. At the very least store the transform value returned so as to avoid making the same function call twice within Update.
You need to look at where the “Player(Clone)” object is being defined/instantiated because it’s evidently not working as you believe.
but by the code
function OnGUI() {
if(GUI.Button(new Rect(20,100,50,50),"up"))
{
GameObject.Find("Player(Clone)").transform.position = new Vector3(0,5,0);
}
}
does Player(clone) well work
this is the tutorial that i use: https://docs.google.com/leaf?id=11Hdqsdp3rFkKzjwqC5Sf1vBQtMs5E2baoJHun9xB-RDyb2jW-uPrbP_P7Gsf&sort=name&layout=list&num=50
Ok - so you’ve established it can find “Player(Clone)” - good.
Now look at the rest of line 7. Break it down bit by bit.
If you comment out the line does it fail on the next line (i.e. does it succeed in setting the TransformDirection or not).
Also - bit of a longshot, but check you have a “Horizontal” input axis defined (can’t see why it would disappear but check anyway)
yes, i have a horizontal input, and the player can rotate but it shows the error, and it willn’t move forward and backward and if i chanche line 7 to transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
then it dont show an error.
For what it’s worth - I created a control.js file that contained your code, added an empty Game Object to a scene, attached a 3rd person controller and dropped your control.js script onto it. I referenced my equivalent to your player (for me it was my main camera).
No errors.
Therefore whatever this script requires to run (a controller, the “Player(Clone)” object, the input axis) is somehow not right.I couldn’t open the link you posted so can’t advise on what you’ve been following.
If you double-click the error message it will position your cursor in your script on the line that’s causing an error.
If you’re still getting a Null Reference Exception, then something on that line is null, but you’re trying to use the . (dot) operator on it.
For example
GetComponent(CharacterController) will be null if there’s no character controller
controller.SimpleMove will then throw a Null Reference exception
GameObject.Find(“X”) will be null if there’s no object exactly named X
GameObject.Find(“Player(Clone)”).transform.Rotate will throw an NRE if there’s no Player(Clone) object or if you’ve somehow removed its Transform
Input.GetAxis(“Blahrgh”) will throw its own, different error if there’s no axis named “Blahrgh”
oke, i do have here the code of the line with null, GameObject.Find ("Player (Clone)"). CharacterController transform.Rotate (0, Input.GetAxis ("horizontale" ) * rotateSpeed, 0);
Did you manually retype that line? There are a number of issues…
Compare …
GameObject.Find(“Player(Clone)”).transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed, 0);
GameObject.Find (“Player (Clone)”). CharacterController transform.Rotate (0, Input.GetAxis (“horizontale” ) * rotateSpeed, 0);
Could you possibly have dropped more than one Control.js script somwhere?
in the real code i dont have the space
my player cann rotate, but it shows the error
and the axis called horizontale is negative a and positive d
and i do have one control script.
is there another way to move my character?