Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Kalabquake · Dec 20, 2015 at 08:09 PM · rotationtransformpositionontriggerenterportal

How to transform a GameObject to an Empty GameObject's position and rotation

Um, I suppose I don't know vector3 very well, but I was working with a portal script i found on the internet and tried to change it to do what I want, which is change my position and rotation to the portal's "spawn" gameobject which is used through public string to be the teleportTo var. The code that I had found on the internet worked for re-positioning, but didn't include the rotation part, and if the portals are placed a certain way, the player flies threw them continuously until the player's momentum has stopped. My change to the code does work, instantiating/deleting a string-ed player, which seems rather inefficient, it lags insanely, and does not let my grab/drop script work, since the player becomes a clone. I'd rather use a transform function, which simply moves & rotates the player. I attempted to a few different ways to get the transform to work, but none ever worked correctly. This code is the imitation of the function in which I want.

var teleportTo : Transform;

var player : GameObject;

function OnTriggerEnter (col : Collider)

{

if(col.gameObject == player)

 {

 Instantiate(player, teleportTo.position, teleportTo.rotation);

     Destroy (player);

}

}

The error I got was "The object of type 'CapsuleCollider' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object." which I understand why that is happening, just thought i'd note it.

What I was wondering was if there was a way which I have not learned (I have checked out the tutorials, some things I just need a better understanding of, as the tutorials understandably dont show every way to use the bit of code) to make the player onEnter of the portal's trigger to go to teleportTo's position and rotation. I would also rather the player lose all momentum than reflect it, it will not be used like valve's portals. Thanks in advance, and I know, I need to study up on coding more, I'm just busy all the time, so I'd rather have the answer and description of why it works better than try to decipher other's codes which don't apply to my issue directly, and are difficult to apply to my issue.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SomeGuy22 · Dec 20, 2015 at 08:35 PM

Seems like a lot of unnecessary work for a simple transform change... Instantiating and deleting are heavy tolls on performance. Instead, replace that code with this:

 player.transform.position = teleportTo.position;
 player.transform.rotation = teleportTo.rotation;

"Momentum" changes should happen within your motor script. Unity's Character Motor has a SetVelocity() function which allows you manually enter a velocity. A velocity of Vector3.zero will stop motion.

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 Kalabquake · Dec 21, 2015 at 08:39 PM 0
Share

@SomeGuy22 It is a bit of work, yes. Thank you for your input, especially the bit about velocity, but the rotation part of the code you gave does not work (I had tried before and it had the error that "player" on the second line wasn't a reference to anything, but now it doesn't have that error). It seems as though it would work when I read it, but it doesn't effect the player's rotation in game play mode.

avatar image Kalabquake · Dec 24, 2015 at 05:03 PM 0
Share

@SomeGuy22 Eh, hmm, I suppose I spoke to soon, I turned smoothness on my character's camera rotation and apparently my character turns really fast to match the cardinal direction it had before teleporting after assu$$anonymous$$g teleportTo's rotation. I'll mess with some scripting later to try to correct this.

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

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

Related Questions

How can I make an object transform to given position and rotation 2 Answers

Enemy not facing player when enter rotation orbit 0 Answers

Car Controls without physics. 1 Answer

How do I change the position of my player model after I rotate it so it's not teleporting? 0 Answers

Quaternion.RotateTowards for camera positions is buggy 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