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 grimofdoom · Feb 08, 2016 at 07:12 PM · vector3.distance

can't use Vector3.Distance with object at origin(0,0,0)

I am using a lot of Vector3.Distance in my script, but I do not think it is too much that it is causing my current problem - which I think may be unity's fault? but I may just be ignorant on this one. One specific Vector3.Distance involves using a GameObject at the origin point (0,0,0). I know it does not work because I am using the vector3.distance to destroy any 'floor' outside that point of space, and the 'floor' at the origin point is the only one not being Destroyed(which the obvious distance is too far away that it should have been destroyed. I even walked passed it- forming the floors around it again(none were created in it)(Line 70 is where the Vector3.Distance is).

 ![using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class BuildManager : MonoBehaviour {
 
     public List<GameObject> floorsMade = new List<GameObject>();
     public List<Vector3> floorSpotsAroundPlayer = new List<Vector3>();
     public List<bool> floorBool = new List<bool> ();
     public GameObject player;
     public GameObject floor;
     public Vector3 currentFloor;
     public Vector3 previousFloor;
 
     public bool startGame;
 
     void Start () {
         startGame = false;
         player = GameObject.Find ("Player");
         floorSpotsAroundPlayer.Add (new Vector3 (0, -50, 0));
         floorSpotsAroundPlayer.Add (new Vector3 (30, -50, 0));
         floorSpotsAroundPlayer.Add (new Vector3 (0, -50, 30));
         floorSpotsAroundPlayer.Add (new Vector3 (-30, -50, 0));
         floorSpotsAroundPlayer.Add (new Vector3 (0, -50, -30));
         floorSpotsAroundPlayer.Add (new Vector3 (-30,-50, -30));
         floorSpotsAroundPlayer.Add (new Vector3 (30, -50, 30));
         floorSpotsAroundPlayer.Add (new Vector3 (-30, -50,30));
         floorSpotsAroundPlayer.Add (new Vector3 (30, -50, -30));
         ClearFloorBool ();
     }
         
     void Update(){
         StartGame ();
         CheckFloorChange ();
     }
 
     public void StartGame(){
         if (!startGame) {//CREATES THE BASE 9 SQUARES THAT STARTS THE GAME AND ADDS THEM TO floorsMade
             startGame = true;
             GameObject temp = Instantiate (floor, floorSpotsAroundPlayer [0], Quaternion.identity) as GameObject;
             temp.transform.parent = gameObject.transform;
             floorsMade.Add (temp);
             previousFloor = GameObject.Find ("GameManager").GetComponent<GameManager> ().currentFloor;
         }
     }
 
     public void CheckFloorChange(){
         currentFloor = GameObject.Find ("GameManager").GetComponent<GameManager> ().currentFloor;
         if (currentFloor != previousFloor) {
             previousFloor = currentFloor;
             foreach (GameObject floor in floorsMade) {//FIND FLOORS SPOTS FILLED,FILL THEM WITH TRUE IN floorBool
                 for (int i = 1; i < 9; i++) {
                     Vector3 tempvect = new Vector3 (floor.transform.position.x - currentFloor.x,-50,floor.transform.position.z - currentFloor.z);
                     if (tempvect == floorSpotsAroundPlayer[i]) {
                         floorBool [i - 1] = true;//MINUS ONE BECAUSE SKIPPED ONE IN THE 'FOR' STATEMENT, WHICH IS EQUAL TO CURRENT FLOOR
                     }
                 }
             }
             for (int i = 0; i < 8; i++) {
                 if (!floorBool [i]) {//INSTANTIATE FLOORS IN false SPOTS IN floorBool 
                     //FLOORS ARE 100 HIGH AND NEED -50 FOR Y FOR PROPER PLACEMENT
                     Vector3 tempVect = new Vector3 (currentFloor.x + floorSpotsAroundPlayer [i + 1].x, floorSpotsAroundPlayer [i + 1].y, currentFloor.z + floorSpotsAroundPlayer [i + 1].z);
                     GameObject temp = Instantiate (floor, tempVect, Quaternion.identity) as GameObject;
                     temp.transform.parent = gameObject.transform;
                     floorsMade.Add (temp);
                 }
             }
             ClearFloorBool ();
             for (int i = floorsMade.Count - 1; i > 0; i--) {//DELETE FLOORS THAT ARE TOO FAR AWAY. BETTER EFFECT AND TOO FAR AWAY IS USLESS
                 if (Vector3.Distance (currentFloor,floorsMade[i].transform.position) > 120) {
                     Destroy (floorsMade[i]);
                     floorsMade.RemoveAt (i);
                 }
             }
         }
     }
 
     public void ClearFloorBool(){
         floorBool = new List<bool> ();
         floorBool.Add (false);
         floorBool.Add (false);
         floorBool.Add (false);
         floorBool.Add (false);
         floorBool.Add (false);
         floorBool.Add (false);
         floorBool.Add (false);
         floorBool.Add (false);
     }
 }][1]

(the lone square is at the origin point)

[1]: /storage/temp/63393-capture.png

capture.png (244.0 kB)
Comment
Add comment · Show 3
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 grimofdoom · Feb 07, 2016 at 03:38 AM 0
Share

I did try reversing the two inside the Vector3.Distance, but that still came up with the same results.

avatar image Vagonn · Feb 08, 2016 at 07:43 PM 0
Share

Try printing this two Vector3(positions) to console. See what showing up

avatar image Owen-Reynolds · Feb 08, 2016 at 08:11 PM 0
Share

Hmmm ... it's a really basic thing that distance(A,B) is the same as distance(B,A). And there's nothing special at all about the point (0,0,0) -- distance to/from (0,0,0) is never a problem.

I'd say, since you we're even thinking that way, restart with some very simple stuff, display as much as you can (as Vagonn suggests) and just get a feel for how it works. You'll probably discover a handful of things that don't work the way you thought they did, and see "what was I thinking" spots in your code above.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

vector 3 to unity.transform 1 Answer

How limit the movement using distance 2 Answers

Vector3.Distance returning offset values due to down force interference. 1 Answer

Distance interaction 0 Answers

Lerp to a fixed distance 0 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