• 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
1
Question by Jerses · Mar 04, 2014 at 08:20 PM · movementpositioningparallel

Limit Y axis of 2 parallel objects

I have two objects that follow the player at the same time but parallel to each other.

player -----> :) A <----- Object A

---------------------------------- Platform A

                B <----- Object B

----------------------------------- Platform B

They move along the X, Z axis but i need limited movement in Y axis so that the object that follow the player can climb stair or go down or anywhere within his platform without going to the other platform. I try mathf.clamp but no luck

 {
                     Vector3 currentPosition = transform.position;
                     currentPosition.x = playerTransform.position.x;
                     currentPosition.z = playerTransform.position.z;
                     currentPosition.y = Mathf.Clamp (playerTransform.position.y, 1, 15);
                     currentPosition += offset;
                     transform.position = currentPosition;     
                 }

  
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 rednax20 · Mar 04, 2014 at 08:50 PM 0
Share

what is this code inside of, an update? an OnTrigger event? an if statement? Your code looks okay. your problem is probably somewhere else; wether it be code, or somewhere else in the scene.

i could use some more help visualizing your problem. You say that the objects are parallel. I usually think of an object as a point. lines are parallel, points are collinear. I am confused what you mean by parallel. I could use a bit more help understanding what you mean

other than that, good luck, i hope you find the answer you are looking for.

avatar image Jerses · Mar 04, 2014 at 09:42 PM 0
Share

Sorry i forgot to post all the script. Im trying to make the player teleport from one world to another.

Player (will have. working on it) a door that he can spawn when he press the Q key. Enters it and travel to the the parallel world and vise verse.

So for this to work Door A and B only moves on x,z Axis. This works ok but every time the player need to climb a ladder or the player moves in the Y Axis then it looses contact with the trigger. Right now the trigger (the door) is touching the player for easy test.

Im also stuck at making does door that follow the player to stop for 5 seconds so the player can enter them. but thats another question. but i will not $$anonymous$$d if anyone can help me too. Oh! and sorry for my bad english im trying my best to communicate my problem. THanks you.

Here is the script

 using UnityEngine;
 using System.Collections;
 
 public class Teleport : $$anonymous$$onoBehaviour {
     
     public Teleport destination;
     public Transform playerTransform;
     public Vector3 offset;
     
     void Update()
     {
         Vector3 currentPosition = transform.position;
         currentPosition.x = playerTransform.position.x;
         currentPosition.z = playerTransform.position.z;
     
         currentPosition += offset;
         transform.position = currentPosition;    
 
 
 
 
 
     }
     
     void OnTriggerStay(Collider other)
     {
         if (other.CompareTag("Player"))
         {
             
             
             if(Input.Get$$anonymous$$eyDown ("q"))
             {  
                 
                 other.gameObject.transform.position = destination.gameObject.transform.position - offset; 
 
 
                 {
                     Vector3 currentPosition = transform.position;
                     currentPosition.x = playerTransform.position.x;
                     currentPosition.z = playerTransform.position.z;
                     currentPosition += offset;
                     transform.position = currentPosition;     
                 }
                 
             }
         }
     }
     
 }
 
avatar image Jerses · Mar 04, 2014 at 09:45 PM 0
Share

alt text

s.jpg (84.6 kB)
avatar image Jerses · Mar 04, 2014 at 11:08 PM 0
Share

The door always follow the player on x and z axis and with an offset so that the player will see where the door will appear. if the player click the key "q" again. then the door will stop following the player and stay in the place, the player can cross the door to the other dimension.

avatar image Jerses · Mar 04, 2014 at 11:13 PM 0
Share
  1. Player summons the portal with a click of the key "q".

  2. a portal appears and the player can move the portal around to see if it fits where he wants...the portal dissapear if the player does not click again the "q" key.

  3. if he press the key then the portal will stop following the player so he can cross between parallel dimensions

  4. cross the portal and the player can again summon the portal to cross back to his initial dimension.

avatar image Jerses · Mar 04, 2014 at 11:23 PM 0
Share

this are my problems. 1. the player does not teleport if he is in a ladder or high ground. becuase its movement is restricted to x,z axis. so i need a way for the portal to be summoned in a restricted Y axis position. thats why i posted this code to see if it was ok

  currentPosition.y = $$anonymous$$athf.Clamp (playerTransform.position.y, 1, 15);

but it does not work because portal B colapse with A

  1. How do you stop the portal from following the player on second key press and add a timer to reset the portal and starts follow again the player?

Thank you for your patience i really appreciate your help.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SirCrazyNugget · Mar 04, 2014 at 11:02 PM

I'm not sure if I understand the problem fully but from what I can make of it: If you want the position of the door to never move on the Y Axis, then never change it but I can't see why you're setting an offset?

If the offset is simply the distance between the two areas then apply the offset to just that axis (so only store it as a float instead of using Vector3).

 float offsetY = 8; //or whatever required value
 
 Vector3 currentPosition = transform.position;
 currentPosition.y += offsetY;
 transform.position = currentPosition;
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 SirCrazyNugget · Mar 04, 2014 at 11:07 PM 0
Share

Or if after spawning a door you could fashion your own trigger, spawn the door, and on Update check the distance between the player and the door ignoring the Y axis?

Sorry again if this is no help, I'm struggling to envisage the whole problem.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

ECS design problem 0 Answers

Radial distance between two points 1 Answer

Smooth continuous movement with fast updating position 0 Answers

Markerless AR 0 Answers

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


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