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 cube · Dec 25, 2011 at 08:10 PM · transformpositionteleport

Transform.Position Help

I want to make like a teleport , changing the position of the first person controller . Here is my script , var person = first person controller :

var person : GameObject ;

function Update () { if (Input.GetKeyDown ("Q")) { person.transform.position.y = 1.381072 ; person.transform.position.x = 56.47888 ; person.transform.position.z = 47.47589 ; } }

Comment
Add comment · Show 2
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 FLASHDENMARK · Dec 25, 2011 at 08:30 PM 0
Share

Yes...And?

avatar image cube · Dec 25, 2011 at 08:40 PM 0
Share

It doesnt work .

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ramonfr · Dec 25, 2011 at 08:49 PM

Try this: person.transform.position = Vector3( 1.381072, 56.47888, 47.47589);

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
avatar image
0

Answer by Lo0NuhtiK · Dec 25, 2011 at 10:07 PM

Put this on your player (or any other object) then drag some other object from your hierarchy onto the "teleport" slot (this will be the end-location after teleporting , I'd create an empty game object to use as the teleport) ; after that, push play, hit the "T" key, and poof... magic.

var teleport : Transform ; //<--Drag object from Hierarchy into this in //the inspector panel, the location to teleport to

@HideInInspector var player : Transform ; //<--the transform of the object this is attached to

function Awake(){ player = transform ; //<--I'm guessing this is why yours wouldn't work. You put } //your person var at the top for caching, but never cached //it's value in awake() or start() ; Either that, or you had //attached your script to some other object and forgot to //drag&drop your player into the slot for 'person'

function Update(){ if(Input.GetKeyDown(KeyCode.T)){ TeleportMe() ; } }

function TeleportMe(){ player.position = teleport.position ; }

Comment
Add comment · Show 2 · 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 cube · Dec 26, 2011 at 12:04 AM 0
Share

it didnt work.

avatar image Lo0NuhtiK · Dec 26, 2011 at 12:08 AM 0
Share

It's something screwy on your end then, because it works fine for me.

avatar image
0

Answer by JerryCic · Dec 26, 2011 at 01:24 AM

Hi

I use c# so my approach is a little different. I have used the vector3 assignment approach rather that the individual x and y and z approach. But!!!! can you be sure that the event is fireing? Place the java equivilant to "Debug.Log("Q entered"); into your assignemnt routine and inspect the console to see if it is getting fired. Maybe a lowercase Q is being processed. If the routine is being processed then you will see a message.

That being said, Instead of polling in the Update cycle, why don't you use the onKeyDown event?

It only gets fired once when the key is pressed. Now again i say that i come from the vb.net (or c#.net) programming world and all my business apps are event driven. I am not sure if this event is available in Java.

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

8 People are following this question.

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

Related Questions

How to transform position? 2 Answers

transform.position sends object to wrong position 1 Answer

transform position player teleport 0 Answers

Transform position? 2 Answers

I'm trying to teleport with a key press, but right now they only teleport for one second. How to fix?,With a key press, no OnTriggerEnter, how to teleport the player? 2 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