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 MrBalin · Mar 02, 2015 at 12:49 PM · raycasttransformpositionteleport

transform position player teleport

I managed to get the player to teleport to a collider surface or variable distance away from the camera into space. The tricky part is where the teleport to space is close enough to a collider that it will teleport me to the other side!

I have a ray cast buoy in place to show that if one of these ray casts hits a collider, that it should make an adjustment to where the player is teleporting. BUT I seem to come across a wall in getting it to work! How should I go about fixing this?

using UnityEngine; using System.Collections;

public class Blink : MonoBehaviour {

 public GameObject blinkPin;
 public float maxDistance = 10f;
 public float blinkArea = .5f;
 
 public static Transform cam;
 
 Vector3 camPos;
 //Vector3 freeBlinkPos;

 GameObject pin;
 GameObject buoy; 

 
 bool teleC = false;
 bool teleN = false;


 // Use this for initialization
 void Start () {
     
     
     
     cam = Camera.main.transform;
     pin = GameObject.Find ("Pin");
     buoy = GameObject.Find ("Marker");
     
     pin.SetActive (false);
     
     
 }
 
 // Update is called once per frame
 void Update () {



     bool foundHit = false;
     
     //add camera local transform and adds maxdistance
     camPos = GameObject.FindWithTag ("Player").transform.Find ("Main Camera").transform.TransformPoint (0,0, maxDistance);

     BlinkHere (foundHit);

     
 }

 void BlinkHere (bool hitCol)
 {
     RaycastHit hitRay = new RaycastHit ();


     //PORTSIDE DETECTOR  PORT
     bool port = false;
     RaycastHit limitP = new RaycastHit ();
     Vector3 portside = buoy.transform.TransformDirection (Vector3.left);
     port = Physics.Raycast (buoy.transform.position, portside, out limitP, 1);
     Debug.DrawRay (buoy.transform.position, portside * 1, Color.red);

     //STARBOARD DETECTOR  STAR
     bool star = false;
     RaycastHit limitS = new RaycastHit ();
     Vector3 starside = buoy.transform.TransformDirection (Vector3.right);
     star = Physics.Raycast (buoy.transform.position, starside, out limitS, 1);
     Debug.DrawRay (buoy.transform.position, starside * 1, Color.green);

     //STERN DETECTOR     STERN  YELLOW
     bool stern = false;
     RaycastHit limitSt = new RaycastHit ();
     Vector3 sternside = buoy.transform.TransformDirection (Vector3.back);
     stern = Physics.Raycast (buoy.transform.position, sternside, out limitSt, 1);
     Debug.DrawRay (buoy.transform.position, sternside * 1, Color.yellow);

     //TOP DETECTOR       TOP
     bool  top = false;
     RaycastHit limitTop = new RaycastHit ();
     Vector3 topside = buoy.transform.TransformDirection (Vector3.up);
     top = Physics.Raycast (buoy.transform.position, topside, out limitTop, 1);
     Debug.DrawRay (buoy.transform.position, topside * 1, Color.cyan);



     //BOW DETECTOR      BOW  MAGENTA
     bool bow = false;
     RaycastHit limitBow = new RaycastHit ();
     Vector3 bowside = buoy.transform.TransformDirection (Vector3.forward);
     bow = Physics.Raycast (buoy.transform.position, bowside, out limitBow, 2);
     Debug.DrawRay (buoy.transform.position, bowside * 2, Color.magenta);
     Debug.Log (bow);




     //BELOW DETECTOR   BELOW
     bool below = false;
     RaycastHit limitBelow = new RaycastHit ();
     Vector3 belowside = buoy.transform.TransformDirection (Vector3.down);
     below = Physics.Raycast (buoy.transform.position, belowside, out limitBelow, 1);
     Debug.DrawRay (buoy.transform.position, belowside * 1, Color.white);



     if (Input.GetButton ("Fire1"))
     {
         hitCol = Physics.Raycast ((transform.position + new Vector3 (0,1,0)), cam.forward, out hitRay, maxDistance);
         pin.SetActive (true);

         //test ceiling
         //Debug.DrawRay (buoy.transform.position, buoy.transform.forward * 3, Color.red);


         if (hitCol) 
         {

             Debug.Log ("switched to teleC porter");
             blinkPin.transform.position = hitRay.point;
             blinkPin.transform.rotation = Quaternion.LookRotation (hitRay.normal);
             blinkPin.transform.Find ("Pin").localPosition = new Vector3 (0, 0, .5f);

             teleN = false;
             teleC = true;

         }


         if (!hitCol) 
         {

             Debug.Log ("switched to teleN porter");
             //make sure to change child cube to 0 0 0 here, and back to original in first if
             blinkPin.transform.position = camPos;
             blinkPin.transform.rotation = transform.rotation * (Quaternion.Euler (-90, 0, 0));
             //dont bother changing the y axis because its simply the plane collision
             blinkPin.transform.Find ("Pin").localPosition = new Vector3 (0, 0, 0);

             teleC = false;
             teleN = true;

         }
     }


     //Blink to Collider TELEC
     if ( Input.GetButtonUp ("Fire1") && teleC)
     {
         Debug.Log ("teleported with teleC");

         //for some reason it adds maxDistance from somewhere, not just teleports to blinkpin
         Vector3 newPos1 = blinkPin.transform.TransformPoint (0, 0, blinkArea);
         transform.position = newPos1;
         pin.SetActive (false);
     }


     //Blink to Null Space  TELEN
     if (Input.GetButtonUp ("Fire1") && teleN)
     {
         Debug.Log ("teleported with teleN");

         //port || star || stern || top || bow || below

         //MAGENTA
         if (bow)
         {
             Debug.Log ("teleported with bow");

             Vector3 newPosBow = blinkPin.transform.TransformPoint (0, 0, -2f);
             transform.position = newPosBow;
             pin.SetActive (false);

         }

         //YELLOW
         /*
         if (stern)
         {
             Debug.Log ("teleported with stern");

             Vector3 newPosStern = blinkPin.transform.TransformPoint (0, 0, .2f);
             transform.position = newPosStern;
             pin.SetActive (false);
             
         }
         */

         //port || star || stern || top || bow || below
         if (!port || !star || !stern || !top || !bow || !below)
         {
             Debug.Log ("teleported without any help");

             Vector3 newPosNull = blinkPin.transform.TransformPoint (0, 0, 2f);
             transform.position = newPosNull;
             pin.SetActive (false);

         }


     }
 }    

}

Comment
Add comment · Show 1
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 hexagonius · Mar 02, 2015 at 03:25 PM 1
Share

Posting 200 lines of code is not cool :(

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

JS Dynamic Height Camera vibrating =( 1 Answer

Negative Positions Breaks Raycasts 1 Answer

Getting transform position of last parent 2 Answers

NullReferenceException when using raycast 1 Answer

Trouble with raycasting 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