• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by laurienash · Jun 09, 2013 at 11:30 PM · transformactive

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Scribe · Jun 10, 2013 at 10:07 AM 2
Share

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

avatar image InfiniBuzz · Jun 10, 2013 at 10:15 AM 0
Share

True, I was focused on the missing x, y and z and completely overlooked that. Thank you I edited

avatar image laurienash · Jun 10, 2013 at 11:19 AM 0
Share

Thanks! That's really helpful :)

avatar image
0

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))
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# GUI.Button Transform.Position 1 Answer

C# GameObjectList not Setting Parent 0 Answers

C# The call is ambiguous between the following methods or properties 1 Answer

Script to set character to active after 3 seconds not working 1 Answer

My Y position goes fixed to some value 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges