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 Dyreo · May 22, 2020 at 09:17 AM · bugcharacter controllerglitch

[WITH IMAGES] Portal teleporter works, but only when walking through very slowly

Hey all. I'm creating a game in which a player is able to pass a portal through a portal and back. The scene looks like this:

alt text

alt text

For some reason, the player does not get teleported to the other portal, unless I walk through the portal very slowly. So the code does function, but just very poorly.

Both portals are made up of a render plane (for the illusion of looking through the portal) and an invisible collider plane. The collider plane has the following script attached:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PortalTeleporter : MonoBehaviour
 {
 
     public Transform player;

     // Receiver is the position of the collider plane of the other portal
     public Transform receiver;
 
     private bool playerIsOverlapping = false;
 
     // Update is called once per frame
     void Update() {
         if (playerIsOverlapping)
         {
             Vector3 portalToPlayer = player.position - transform.position;
             float dotProduct = Vector3.Dot(transform.up, portalToPlayer);
 
             // If this is true: The player has moved across the portal
             if (dotProduct < 0f)
             {
                 //Teleport him!
                 Debug.Log("Teleport!");
                 float rotationDiff = -Quaternion.Angle(transform.rotation, receiver.rotation);
                 rotationDiff += 180;
                 player.Rotate(Vector3.up, rotationDiff);
 
                 Vector3 positionOffset = Quaternion.Euler(0f, rotationDiff, 0f) * portalToPlayer;
                 player.position = receiver.position + positionOffset;
 
                 playerIsOverlapping = false;
             }
         }
     }
 
     void OnTriggerEnter(Collider other)
     {
     playerIsOverlapping = true;
     Debug.Log("Player is now overlapping");
     }
 
     void OnTriggerExit(Collider other)
     {
     playerIsOverlapping = false;
     Debug.Log("Player is no longer overlapping");
     }
 }

Is something wrong with my code? I've followed this tutorial step by step, yet the player gets teleported very inconsistently or not at all.

I hope I've given you enough information. Thanks a lot for your time and help!

337d4efeb893eff9d57c4c664cdf945e.png (319.1 kB)
3a64c292dc1ab1c62616379e63f90df4.png (236.5 kB)
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
1

Answer by Azehlf · May 22, 2020 at 01:16 PM

Hello ! I'm not very experienced but it may have something to do with Collision Detection in the Rigidbody 2D : https://docs.unity3d.com/Manual/class-Rigidbody2D.html Setting it to "Continuous" instead of "Discrete" may solve the issue. Hope it helps !

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 Dyreo · May 22, 2020 at 02:41 PM 0
Share

Thanks for your help! Unfortunately I don't think that's the issue because my Player (Character controller) actually doesn't use a Rigidbody.

These are the components of the Player and the ColliderPlane.

alt text alt text

ec948d70b699ac66018270181e4553a7.png (33.3 kB)
e3b89c6e786397e42f0c56c91a9b6914.png (39.9 kB)
avatar image Azehlf Dyreo · May 22, 2020 at 03:06 PM 0
Share

Hmmm, maybe try with fixupdate, if you have a slow pc it may not have the time to update correctly. Does the "OnTriggerEnter" message displays at high speed collision ?

avatar image Dyreo Azehlf · May 22, 2020 at 03:39 PM 0
Share

Actually, now that you mention it: yes. The console does report overlapping every time I pass through the gate. It even displays 'Teleporting!' accordingly, every single time. So the only issue then is that the player doesn't get teleported each time.

So I suppose that line 25 through 34 do not function well?

Show more comments

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

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

Object Changing Y Coordinate in Game View 0 Answers

Strange graphical bug in Editor GUI 1 Answer

Lighting bug Unity? 0 Answers

Flickering issue when objects touch terrain. 1 Answer

Character moves on its own 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