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 /
  • Help Room /
avatar image
0
Question by Atheos D. UnityGenius · Nov 06, 2015 at 01:46 PM · collisioncolliderstransform.positionboxcolliderdoors

How can i find the world position of collider?

So I'm trying to create collision without the onCollisionEnter2D function.

The way I'm doing so is with calculating the distance between the player and my door.

I've tryed many things, and non worked...

Here is an example of what I'm trying to do (After collecting all coins, the door is moving, but the door's boxCollider is staying in place, I'm trying to calculate the distance between the player and the door's boxCollider, the first problem was that the boxColider was on local position of the door, i overcome this with TransformPoint, but now the problem is that it shows me the position of the box collider on the exact position of the door object, which is not true since the door moved and the collider stayed, this is my code :

 public GameObject door; //Door reference.
 public float distancePlayerDoor; //Check distance between player and door.
 public BoxCollider doorMove; //Reference doors collider.

 void Win(){
         //Winning condition, open door, exit, finish menu.

     Vector3 temp = door.transform.position; //Reference door position.
     temp.x = -181.0f; //Move door in X.
     temp.y = 10.0f; //Move door in Y. (Not needed).
     temp.z = -185.0f; //Move door in Z. (Not needed).
     door.transform.position = temp; //Fix door position.

     doorMove.isTrigger = true; //Turn on the doors trigger for collision.
     Vector3 temp2 = doorMove.center; //Reference door box collider left for collision.
     temp2.x = -1.0f; //Leave the doors collider at its place.
     doorMove.center = temp2; //Fix the door box collider position.

     Vector3 temp4 = doorMove.transform.TransformPoint (Vector3.zero);
     temp4.y = 0.0f;

     distancePlayerDoor = Mathf.Sqrt (temp4.x * temp4.x + temp4.z * temp4.z);
     Debug.Log (temp4);

// Vector3 temp3 = doorMove.transform.position-player.transform.position; //Reference the door vectore position minus player vector position. // temp3.y = 0.0f; //Reset the y=0, because if: Y < 0 < Y then Y = 1 or Y = -1, the distance will always grow up or down. // // distancePlayerDoor = Mathf.Sqrt (temp3.x temp3.x + temp3.z temp3.z); //Square the door vectore and the player vectore to get the new vectore of distance.

     if (distancePlayerDoor < 10.0f) { //Check if player is on the door.

         Destroy (game); //Destroy all the game elements.
         Destroy (Scene1); //Destroy all the Scene elements.
         Destroy (loseBG); //Destroy the losing menu.

     } //Check if player is collided with the door.

 } //Create the wining aspects of opening the door and checking that player got to the exit.


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

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

Destroy object on collision not working 1 Answer

Why is my Character's BoxCollider getting stuck in between two wall BoxColliders? 0 Answers

Collider seems bigger than it is 0 Answers

Question on Physics.Simulate Behavior 0 Answers

BoxCollider not blocking other object(s) 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