I’ve never asked a question here before but I’m really stumped so i thought i’d give this a shot.
I’m trying to make a dungeon generator for a rouguelike i’ve been working on, and i’m using my own method to generate the tiles and walls. the tiles and walls generate fine initially, using a raycast to check if blocks and tile are already there before placing new ones. When I try to fill in holes with more wall blocks, the code seems to mess up, and the raycast I set up is ignored. Basically, the walls generate whether there is a tile there or not.
the code is this:
`using UnityEngine;
using System.Collections;
public class wallscript : MonoBehaviour {
public Transform wallloc;
public GameObject wall;
public float radius;
// Use this for initialization
void Start () {
StartCoroutine(mycoroutine());
}
IEnumerator mycoroutine(){
yield return new WaitForSeconds(7);
wallfill();
yield return new WaitForSeconds(9);
wallborders();
}
void wallfill(){
if(!Physics.Raycast(wallloc.position, Vector3.right, 1)){
Debug.Log ("good");
Instantiate(wall,wallloc.position+(wallloc.right), wallloc.rotation);
}
}
void wallborders(){
}
}'
the debug log even tells me there is nothing to the right of the wall, even though there is a tile already there. Does anyone have any idea as to why this is?
Thanks in advance!!
In wallfill() add Debug.Log(wallloc.position); to see what the actual transform is just before the Raycast
– meat5000@ meat5000 I get a lot of numbers by doing that, since there's many wall blocks in the stage. They're not very coherent. I don't see much of a pattern.
– sullivanshadWell there's your problem :) wallloc.position should be completely coherent if you are trying to find what is 1 unit to the right of it. It should give you three numbers; x, y and z coordinates. Point is with void wallfill(){ Debug.Log(wallloc.position); if(!Physics.Raycast(wallloc.position, Vector3.right, 1)){ you should be able to determine which space or block the Raycast is shooting at and see for yourself it is correct.
– meat5000