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 /
avatar image
0
Question by Kronos823 · Oct 01, 2017 at 04:59 AM · movementportalsdirections

How to change the movement direction between portals?

I'm making a game similar to Portal and already done the teleporter. But when the Player or other object enter on the first portal and is teleported to de other portal, he keeps the same trajectory. I wish the trajectory of the object changes based on the position of the portal. Ex: If Player or other object enter in a vertical Portal, but the other portal is in horizontal position, the Player is launched up. This is what I've already did.

 using UnityEngine;
 using System.Collections;
 
 public class ObjetoPortalavel : MonoBehaviour {
     public GameObject ThisObject;
     public GameObject Portal1; 
     public GameObject Portal2;
 
     void OnCollisionEnter2D(Collision2D collision)
 
     {
         Portal1.GetComponent<Collider2D>().enabled = true; 
         Portal2.GetComponent<Collider2D>().enabled = true;
         
 
 
         if (collision.gameObject.tag == "Portal1")
         {
             ThisObject.transform.position = Portal2.transform.position;
             ThisObject.transform.eulerAngles = Portal2.transform.eulerAngles;
             
 
             Portal2.GetComponent<Collider2D>().enabled = false;
            
         }
 
 
 
         if (collision.gameObject.tag == "Portal2")
         {
             ThisObject.transform.position = Portal1.transform.position;
             ThisObject.transform.eulerAngles = Portal1.transform.eulerAngles;
 
             Portal1.GetComponent<Collider2D>().enabled = false;
 
            
         }
 
 
     }
     
     
     // Update is called once per frame
     void Update () {
 
         Portal1.gameObject.tag = "Portal1";
         Portal2.gameObject.tag = "Portal2";
 
 
         
     }
 }
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 FernandoGBR · Oct 01, 2017 at 07:52 AM

How are you moving your character?

I think if you make your players move by applying forces to them, and then you suddenly change their positions and rotations. It shall present a portal-like behaviour.

In case the above does not works a more complex solution would involve saving the relative speed (or kinetic energy) to the entrance portal (taking into account the relative rotation) moving the player to the other portal (as you do now) and then appying the player the same relative kinetic energy but now to the second portal.

Hope this help.

Comment
Add comment · Show 1 · 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 Kronos823 · Oct 03, 2017 at 07:30 AM 0
Share

You're right! I think is how I move my character as you said. I made some changes in the script and discovered how to make what I want. And now works to any objects with this new Script. But the Player still getting problems. I'm using the standard Player's Script from the Unity, so the problem can be this. I'll make my own script to control the "Player" and see if this solve the problem. Thank's bro... Sorry for this bad english haha

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

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

Why does the player keep pointing in a specific direction after moving? 0 Answers

rigidbody.MovePosition in More than One Direction 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Movement with infinite directions acceleration 1 Answer

Making a bubble level (not a game but work tool) 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