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 finae · Jan 03, 2014 at 07:15 AM · gameobjectvariableassign

is there a way to assign north south to an object?

Hi,

I am pretty new to unity3d, so i m asking in hope that there's someway to this. what i m trying to do is have a panel, the panel would have two cube on each side of the panel. the two cube is 10x, 5y,and 1z. sitting on each edge of the panel, so you have a walkway for a hall. all of this is inside an empty gameobject call hallway

I want to be able to have another gameobject look at the hallway object and determine if its looking at the side with the cube or if the side its facing is the side without the cube. The hallway object can can randomly turn 90 %. the second object cannot touch the hallway object.

I hope i m explaingin this correctly.

Comment
Add comment · Show 2
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 ShadoX · Jan 03, 2014 at 07:47 AM 0
Share

An illustration would probably help , but the general idea would be that you have to figure out if object B is visible to object A and check if B is facing the right way. It depends on how precise all that has to be. If your trying to make a simple puzzle similar to the light puzzles in certain games where a beam of light would go from object A to B to C and so on... the easiest would probably be to use a RayCast.. if it's a matter of B being visible to A.. then you could try to do it other ways.

You could try using cameras for that and do something like http://answers.unity3d.com/questions/8003/how-can-i-know-if-a-gameobject-is-seen-by-a-partic.html but it would probably be better if you'd find some other way to do that ins$$anonymous$$d of having multiple cameras for that

avatar image finae · Jan 03, 2014 at 09:03 AM 0
Share

What I am doing is randomizing GO that contains panels and walls to make a maze. and then randomizing a spawn point for the player. the problem is that the player can spawn on a set of panels that is part of the GO which are all block and cannot exit out due to how each GO rotates (also being randomly chosen.

this way when playing the game again the next time the maze is completely different than it was before.


edit: I got it to working via adding a script to the GO that will validate if it turn or not, and the main script will check the GO's component for the variable, it it holds true it turned, so it will then turn with it as well.

the maze now has not block after running it a few dozen times just to check and increasing the size value of the maze to 500 panel (each panel is 10 unit). and no block, but it not completely randomize as it depends on teh one before and the below it. alt text

This gives me a new map each time i replay the scene, even though there's still some $$anonymous$$or bug on it.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by BigRoy · Jan 03, 2014 at 10:30 AM

You could take the position of both cubes and subtract the viewer's position from it. This way you get a vector from the viewer to the cubes.

 Vector3 Vcube1 = Cube1.position - Viewer.position;
 Vector3 Vcube2 = Cube2.position - Viewer.position;
 Vector3 LookDirection = Viewer.forward;
 
 float dotCube1 = Vector3.Dot(Vcube1.normalized, LookDirection);
 float dotCube2 = Vector3.Dot(Vcube2.normalized, LookDirection);

The one with the higher dot product is the one that is mostly in line with the look direction so is likely to be the one you're looking at.

Looking at the comments on the original post I probably misunderstood the question.

Checking if you're looking at the cube or the opposite direction

You can check whether you're looking at the cube or not with a single dot product of that cube with the LookDirection. If it's above 0 it's ranging from almost perpendicular to looking at the object to fully looking at the object. If it's below 0 it's ranging from almost perpendicular to facing away from the object. And zero would be perpendicular.

Assuming the vectors were normalized before you got the dot product you can easily get the angle by doing:

 float angle = Mathf.Acos(dotProduct);

Otherwise you'll have to do:

 float angle = Mathf.Acos(dotProduct / (V1.magnitude & V2.magnitude));

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
avatar image
0

Answer by finae · Jan 05, 2014 at 06:09 AM

You completely lost me , as mentioned i m still pretty new to unity3d. I did however tried a few scenarios and found that i can attach a custom property to the empty GameObject (GO) during runtime as all GO for the maze is generated at Runtime via Resources.Load().

what i end up doing:

public class wProperties : MonoBehaviour public class wProperties : MonoBehaviour{ bool bForward; bool bBack; bool bLeft; bool bRight;

   public setAvailPath(bool isAllow, iType){
      switch(iType)
      {
         case 0: 
            bForward=isAllow;
            break;
         case 1:
            bBack=isAllow;
            break;
         case 2:
            bLeft=isAllow;
            break;
         case 3:
            bRight=isAllow;
            break;
      }
    
     public bool getForward(){return bForward;}
     public bool getBack() {return bBack;}
     public bool getLeft() {return bLeft;}
     public bool getRight() {return bRight;}
 }

on the main script, i would reference the script component to the GO and ask if forward/backward (z coord) is available, or left/right (x coord). if it is not, than i can re-randomize the current GO with a different maze piece.

I have not completely tried but on the generator project but did test the properties above on a new project and the values returned as needed.

Thanks.

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

20 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

Related Questions

Remove object assignment in runtime? 1 Answer

How can I assign a GameObject to a variable at runtime? 0 Answers

Assign a gameobject in a scene to a varible automatically? 0 Answers

Keeping old GameObject values 1 Answer

Raycast object tag check? 3 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