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 eitanwass · May 06, 2016 at 12:45 PM · rotationquaternionteleportforwardportal

Rotating object to another objects rotation [C#]

Hi! A little background: I have asked this question before and i thought it worked but now it doesn't work on some situation. I want to teleport my player to another place when he enters the portal and rotate him to thew portals exit. So when my exit portal is on the ground the player exits and is turning upwards(z = 270)! Code:

 using UnityEngine;
 using System.Collections;
 
 public class StepThroughPortal : MonoBehaviour
 {
 
     public GameObject otherPortal;
     public GameObject player;
 
     Quaternion rotate;
     
     void Start()
     {
         //rotate = Quaternion.LookRotation(otherPortal.transform.forward);
     }
     void Update()
     {
 
     }
     public void Interact(Transform collidedObject)
     {
         Debug.Log("something hit the portal");
         collidedObject.position = otherPortal.transform.position + otherPortal.transform.forward;
         collidedObject.rotation = Quaternion.LookRotation(otherPortal.transform.forward);
         TrackVelocity velocityScript = collidedObject.GetComponent<TrackVelocity>();
         if (velocityScript != null)
             collidedObject.GetComponent<Rigidbody>().velocity = Quaternion.FromToRotation(transform.forward, -otherPortal.transform.forward) * velocityScript.Velocity;
     }
     void OnCollisionEnter(Collision collidedObject)
     {
         Interact (collidedObject.transform);
     }
 
 
 }


Special request for help: @dhore who have helped me in the previous question greatly! Thanks in advance. Ethan

Comment
Add comment · Show 6
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 dhore · May 09, 2016 at 10:40 AM 0
Share

Sorry, I was away with friends over the weekend :3 Glad to see that you fixed it though!

avatar image eitanwass dhore · May 10, 2016 at 03:06 AM 0
Share

Actually now i was debugging again and when i get out of the portal it doesn't change the player rotation to the portal direction.... If you still can please help me. $$anonymous$$y code is as it is written before. Thanks Ethan

avatar image dhore eitanwass · May 10, 2016 at 12:23 PM 0
Share

1) Not sure what that part about the TrackVelocity script is, but it seems to be spinning it in circles or something? $$anonymous$$aybe remove those 3 lines?

2) Ins$$anonymous$$d of collidedObject.rotation = Quaternion.LookRotation(otherPortal.transform.forward); you should just be doing collidedObject.rotation = otherPortal.transform.rotation;

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by he77789 · Nov 23, 2018 at 11:40 AM

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TeleportHandler : MonoBehaviour {
     public Transform otherPortal;
     private TeleportHandler portal;
     [HideInInspector]
     public bool ready = true;
     // Use this for initialization
     void Start () {
         portal = otherPortal.GetComponent<TeleportHandler>();
         Debug.Log(transform+" to "+portal);
         ready = true;
     }
     
     // Update is called once per frame
     void Update () {
         
     }
     private void OnTriggerEnter(Collider other)
     {
         Debug.Log("Enter");
         ready = false;
         if (!portal.ready) return;
         Debug.Log("Transfer");
         Vector3 delta = new Vector3(transform.position.x - other.transform.position.x, transform.position.y - other.transform.position.y, transform.position.z - other.transform.position.z);
         other.transform.position = new Vector3(otherPortal.position.x - delta.x, otherPortal.position.y - delta.y, otherPortal.position.z - delta.z);
         other.transform.Rotate((Quaternion.Inverse(transform.rotation) * Quaternion.Inverse(otherPortal.rotation)).eulerAngles);
     }
     private void OnTriggerExit(Collider other)
     {
         Invoke("Reset", 0.1f);
     }
     private void Reset()
     {
         ready = true;
     }
 }


 Sorry for the lengthy code, that was what I used. However, it does not rotate inertia correctly. See <a href="https://answers.unity.com/questions/1574323/how-to-rotate-a-gameobjects-inertiahow-to-rotate-g.html">My Question</a>
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

64 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 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

Rotation working within an if statement but not within a method??? 0 Answers

Rotating a forward vector 0 Answers

Rotating an Object (To Face Another Object) Only on X and Y Axis 3 Answers

Cancel out the steering rotation returned from a wheel colliders .GetWorldPose(out pos, out rot); 1 Answer

How to make a 2D sprite rotate towards a specific point while facing perpendicular to the camera ? 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