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 sullivanshad · Nov 20, 2013 at 09:17 PM · c#raycastgenerated

Something wrong with the raycast

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!!

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 meat5000 ♦ · Nov 20, 2013 at 09:21 PM 0
Share

In wallfill() add

Debug.Log(wallloc.position);

to see what the actual transform is just before the Raycast

avatar image sullivanshad · Nov 20, 2013 at 10:35 PM 0
Share

@ 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.

avatar image meat5000 ♦ · Nov 20, 2013 at 10:37 PM 0
Share

Well 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 deter$$anonymous$$e which space or block the Raycast is shooting at and see for yourself it is correct.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by OP_toss · Nov 20, 2013 at 10:50 PM

You raycast to the world-space right direction (Vector3.right), but then you instantiate to the local wallloc.right direction. These are 2 different values that depend on the rotation of wallloc. If wallloc is rotated, this seems like it could cause problems.

Also, please use camel case. I stared at "wallloc" for a while until I understood it was "wall" + "loc".

Also it seems like since you have this in a coroutine, that you want it to build multiple walls iteratively. Does that mean you meant to move "wallloc" after instantiating a wall? As it is, wallloc doesn't move, so it should keep checking the same spot and keep instantiating at the same spot. Maybe we're not seeing all the code involved?

Hope that helped!

Comment
Add comment · Show 1 · 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 sullivanshad · Nov 20, 2013 at 11:17 PM 0
Share

@OP_toss

I tried changing the instantiation so it matches the world space of the raycast, but no dice.

I had a theory that the raycast is either missing the tiles because they're so low, or the raycast only reads the wall blocks and not the tiles.

and sorry about forgetting the camel case, i'm relatively new to program$$anonymous$$g, and it completely slipped my $$anonymous$$d.

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

19 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

Related Questions

How can i modify a float in another script in C#? 1 Answer

Distribute terrain in zones 3 Answers

Automatic Node Connection - Help 1 Answer

How to select an object with TOUCH and change its animation 2D 1 Answer

Multiple Cars not working 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