Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Moltvatch · Feb 15, 2011 at 12:43 PM · cameratransformpositionteleport

How to transform position?

Can someone show me the script to teleport an object? I mean to transport it to another position?

here is what I did :

var player = gameobject.find("Cam1");

funtcion update () { If input.getkeydown("e") transform.position = var player (0,0,0 )

well it seems cr** to me.

Im realy need help on this one guys, please.

Comment
Add comment · Show 1
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 · Feb 15, 2011 at 01:19 PM 0
Share

You really need to take care with spelling and capitalisation of function names. Take a look at $$anonymous$$ike's answer for how to fix your problems, but as an example, it's '`GameObject.Find()`' and '`Input.Get$$anonymous$$eyDown()`'. Check the Script Reference if you're unsure.

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Mike 3 · Feb 15, 2011 at 01:17 PM

You want something along the lines of this:

var player = GameObject.Find("Cam1");

function Update () {

 if (input.GetKeyDown(KeyCode.E))
 {
     //i'm not sure what you were trying to do here, so i'll add in 3 examples of what you could do

     //bring the object to the player
     transform.position = player.transform.position;

     //bring the player to the object
     player.transform.position = transform.position;

     //move the player to 0,0,0 - you can also use Vector3.zero instead of Vector3(0,0,0)
     player.transform.position = Vector3(0,0,0);
 }

}

Edit:

function OnTriggerStay(other : Collider) {
    if (Input.GetKey(KeyCode.E))
    {
        var player = GameObject.Find("First Person Controller");
        player.transform.position = Vector3(-20391,10598,-25495);
    }
}
Comment
Add comment · Show 4 · 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 Moltvatch · Feb 15, 2011 at 02:07 PM 0
Share

IT WOR$$anonymous$$S!! THAN$$anonymous$$ YOU DUDE!!

Seriously! Three days I've been asking how to do this! Three days I've been trying different things... for this simple piece of code...

Anyway thanks. By the way, I've got to set the trigger button on for the mesh collider. Is there a way to make the mesh being a true collider because with this set on the mesh doesnt collide anymore with the fps controller.

Or is it better that I make an other "invisible" object to put this script on?

avatar image Mike 3 · Feb 15, 2011 at 03:16 PM 0
Share

If a meshcollider isn't working, you could try click the box for making the mesh collider convex. If that isn't working, there could be something else wrong, but otherwise sure, add another object with colliders

avatar image Moltvatch · Feb 15, 2011 at 03:51 PM 0
Share

thank you, everything is fine anyway.

You're saving me.

avatar image alok-kr-029 · Apr 11, 2013 at 10:45 AM 0
Share

thanks buddy this was helpful

avatar image
0

Answer by Moltvatch · Feb 15, 2011 at 01:29 PM

Here is what I did :

function Update () { var player = GameObject.Find("First Person Controller");

}

function OnTriggerStay(other : Collider) { if (Input.GetKeyDown(KeyCode.E)) { //move the player to 0,0,0 - you can also use Vector3.zero instead of Vector3(0,0,0) player.transform.position = Vector3(-20391,10598,-25495);

     }

It tells me that player is unknown. "unknown identifier player"

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.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Camera movement 1 Answer

Place a object in front the camera in the coordinate 0 of Y axis 2 Answers

Trouble converting transform.position to C# 1 Answer

How to make Main Camera to not follow object on Y 3 Answers

Following a gameObject, unexpected problems? 1 Answer


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