- Home /
How to instantiate controller at specific rotation (Error: It is not possible to invoke an expression of type 'UnityEngine.Quaternion'
Hi - when my third person controller hits a collider, he is destroyed, and a new third person controller is instantiated in the exact same position. However - I also want him to be rotated 180 degrees (so facing backwards).
This is the line of code that is giving me an error: carl.transform.Rotate (0, 180, 0);
Do you know what I'm doing wrong?
This is the script to instantiate a new third person controller (JavaScript):
var carl : GameObject;
var vincentCamera : GameObject;
var thirdPerson : GameObject;
var script : SwitchCharacters;
var playerGO : GameObject;
private var hasPlayed = false;
var characterPosition : Vector3;
function Start () {
carl.SetActive (false);
vincentCamera.SetActive (false);
}
function OnTriggerEnter () {
if (!hasPlayed&&!thirdPerson.active){
characterPosition = GetComponent(DestroyCharacter).firstCharacterPosition;
carl.transform.position = characterPosition;
carl.transform.Rotate (0, 180, 0);
carl.SetActive (true);
vincentCamera.SetActive (true);
script.cam02 = carl.Find("VincentCamera");
script = playerGO.GetComponent(SwitchCharacters);
script.player02 = carl;
hasPlayed = true;
}
Any help on how to fix the error would be so much appreciated! The error is BCE0077: It is not possible to invoke an expression of type 'UnityEngine.Quaternion'.
Thanks, Laurien
Answer by ExTheSea · Jun 09, 2013 at 07:01 PM
You have to do:
carl.transform.Rotate(new Vector3(0, 180, 0));
as can be seen here too: http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html
Right i just noticed that. Hm in this case if this doesn't work i would suggest just to use something like this:
carl.transform.rotation = new Vector3(0,180,0);
When you use transform.rotate you normally multiply the value by Time.deltaTime or similar to get a smooth rotation-effect. $$anonymous$$aybe the method is complaining because of that.
Transform.rotation is a quaternion, not a vector3. In order to set the rotation of a transform, either supply a quaternion that has been derived from some calculation (I.e. don't modify xyzw values of quaternions directly), or set transform.eulerAngles wih a vector3 ins$$anonymous$$d.
Yes I had read that - I didn't realise you needed to add the new
Thanks!
Your answer
Follow this Question
Related Questions
C# Need Help Refining Ricochet Script 1 Answer
[SOLVED]Possible Alternation of Transform.Rotate 1 Answer
Change Pivot Point- Maya 3 Answers
Min-Angle Constraint Script Causes Jitter 0 Answers
Camera rotation C# script problem 3 Answers