Quantcast
Channel: Answers by "M-G-Production"
Viewing all articles
Browse latest Browse all 52

Answer by M-G-Production

$
0
0
First you should consider storing that 'wall' into a local variable to increase performance. Then you should use position instead of localPosition (position is the real world position, localPosition is the position as child relative to its parent.) Finally, I'd say that the chance of the wall being exactly at the same place could be pretty hard to validate (depending on the way you are programming your game)... You could create a method that could compare the values with a certain distance... Adjust your script like this: GameObject theWall; public void update() { if (theWall == null) theWall = GameObject.FindGameObjectWithTag("wall"); if (AreNear(theWall.transform.position, gameObject.transform.position, 0.1f)) { //Something Happens } } //This method detects if the object are close depending on minDistance value bool AreNear(Vector3 obj1, Vector3 obj2, float minDistance = 0) { return ((obj1.x < obj2.x + minDistance && obj1.x > obj2.x - minDistance) && (obj1.y < obj2.y + minDistance && obj1.y > obj2.y - minDistance) && (obj1.z < obj2.z + minDistance && obj1.z > obj2.z - minDistance)); }

Viewing all articles
Browse latest Browse all 52

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>