- Home /
carl.transform.position = characterPosition -- how to set to this specific position but -3 on x axis?
Hello - when my third person controller walks into a collider, he is destroyed, and a new third person controller is set to active in the exact same position, but rotated 180 degrees.
This script works - but I would like the character to be set in the same position as the first third person controller, but -3 on the x axis. I just can't work out how to script this correctly - I tried this line:
carl.transform.position(new Vector3(characterPosition-3, characterPosition, characterPosition));
But this came up with a lot of errors. How do I transform a character to this character position, but -3 on the x axis?
This is my SetCharacterToActive script (JavaScript):
var carl : GameObject;
var vincentCamera : GameObject;
var thirdPerson : GameObject;
var script : SwitchCharacters;
var playerGO : GameObject; //Should be filled with the GameObject the SwitchCharacters script is attached to
private var hasPlayed = false;
var characterPosition : Vector3;
function Start () {
carl.SetActive (false);
vincentCamera.SetActive (false);
}
function OnTriggerEnter () {
if (!hasPlayed&&!thirdPerson.active){
characterPosition = GetComponent(DestroyCharacterVincent).firstCharacterPosition;
carl.transform.position = characterPosition;
carl.transform.Rotate(new Vector3(0, 180, 0));
carl.SetActive (true);
vincentCamera.SetActive (true);
script.cam02 = carl.Find("VincentCamera");
script = playerGO.GetComponent(SwitchCharacters);
script.player02 = carl;
hasPlayed = true;
}
}
Thanks so much, Laurien
Answer by InfiniBuzz · Jun 10, 2013 at 12:12 AM
hi
Instead of using
carl.transform.position(new Vector3(characterPosition-3, characterPosition, characterPosition));
try
carl.transform.position = Vector3(characterPosition.x - 3, characterPosition.y, characterPosition.z);
E: The position property is of course no method, thanks to Scribe
I might be wrong but I don't think you can invoke/call position(vector3), if it does work disregard this comment! Otherwise maybe this was meant:
carl.transform.position = Vector3(characterPosition.x - 3, characterPosition.y, characterPosition.z);
Scribe
True, I was focused on the missing x, y and z and completely overlooked that. Thank you I edited
Answer by Mukabr · Jun 10, 2013 at 12:19 AM
Well, you're forgetting the x,y and z. This is the right form
carl.transform.position(new Vector3(characterPosition.x-3, characterPosition.y, characterPosition.z))
Your answer
Follow this Question
Related Questions
C# GameObjectList not Setting Parent 0 Answers
C# Transform Issues 1 Answer
C# The call is ambiguous between the following methods or properties 1 Answer
C# Smoothing Out transform.Translate 4 Answers
C# GUI.Button Transform.Position 1 Answer