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 dendens2 · Apr 16, 2013 at 03:25 AM · c#javascriptconvert

C# to UnityScript conversion help.

So I am trying to translate a A* path finding script(a part of it at least) to UnityScript. I have gotten it to run without errors, but not run correctly. I is supposed to make a grid covering the area of the cube(in my case it is an invisible square covering my level. To test out if it works before continuing on, I made it so that it instantiates cubes. It ended up making four rows of stair-like figures. Can you guys please look at my code and tell me what I am missing?

http://puu.sh/2AZuk http://puu.sh/2AZuQ

Mine:

 class GridCell
 {
 var cellWalkable: boolean;
 var cellHeight: float;
 
 //Width and height of the map (in cells)
 var mapWidth: int;
 var mapHeight: int;
 }
 
 var cellSize: float = 0.5;
 var bounds: Bounds;
 var topLeftCorner: Vector3;
 
 //Map of the world
 var gridCells = new Array();
 
 var square: GameObject;
 
 function Start () 
 {
 
         bounds = renderer.bounds;
 
 
 }
 
 function Update () 
 {
 //Scans the bounds of the model, then creates a grid
     //Finds the top left corner
     topLeftCorner = bounds.center - bounds.extents + Vector3(0, bounds.size.y, 0);
     
     //creates the grid map
      var cells = GridCell();
     
     //Calculates the dimensions of the grid map.
     cells.mapWidth = Mathf.RoundToInt(bounds.size.x / cellSize);
     cells.mapHeight = Mathf.RoundToInt(bounds.size.y / cellSize);
     //Scans for walkable terrain in each cell
     for(var x = 0; x < cells.mapWidth; x++)
     {
         for(var y = 0; y < cells.mapHeight; y++)
         {
             //Gets the position for a ray
             var currentPosition = topLeftCorner + Vector3(x * cellSize, 0, y * cellSize);
             var hit: RaycastHit;
             //Creates a cell for the grid
             var cell = new GridCell();
             
             //Cast the ray
             if(Physics.Raycast(currentPosition, Vector3(0, -1, 0),hit, bounds.size.y))
             {
                 //the height of the highest item in the cell
                 cell.mapHeight = hit.point.y;
                 //Test if the hitpoint is walkable
                 Instantiate(square, hit.point, Quaternion.Euler(0,0,0));
                 if(((1 < hit.collider.gameObject.layer) /*&& walkableLayer*/) !=0)
                 {
                     //Flag the cell we hit as walkable
                     cell.cellWalkable = true;
                 }
             }
         }
         
     }
 
 }


His: He has a site that he posted this on http://unitygems.com/astar-1-journeys-start-single-step/ To be more specific it is the part in this picture. http://puu.sh/2AZCy

THANK YOU!

Comment
Add comment · Show 5
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 whydoidoit · Apr 16, 2013 at 09:08 AM 0
Share

It looks to me like square has a box collider on it. In that case it will hit the box when it tests the next cell. Also there's no need for the if(((1 > hit.collider.gameObject.layer code if you aren't testing for a specific walkable layer you could just make the cell walkable immediately.

I recommend though:

You put the walkable parts of the level on their own layer.

You specify a walkable layer property and set it to the layer (that way you won't be able to walk on enemies, trees etc).

avatar image dendens2 · Apr 17, 2013 at 02:47 AM 0
Share

Ok, so removing the collider fixed that issue, but It is still not going through the whole area. Also, I haven't added the separate layer yet, so some of the cells do appear on the tops. I am guessing it is a problem with either mapHeight or mapWidth. Thanks.

avatar image dendens2 · Apr 17, 2013 at 04:36 AM 0
Share

Also, is there a better way to debug this. I am currently displaying the grid cells and that causes Unity to usually freeze. Is there another way?

avatar image dendens2 · Apr 17, 2013 at 11:33 PM 0
Share

Oh wow. Now I feel stupid. I was not understanding why the SQUARES (not cells) were not spawning far away from each other, when the code is only set to make the CELLS spawn far away from each other. lol

avatar image dendens2 · Apr 18, 2013 at 02:27 AM 0
Share

Oh wait. It was actually the fact that I had it measure the distance on the wrong axis. I was thinking of the 3dsmax y axis. To anyone who wants to know.

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

12 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

Related Questions

Help with conversion from javascript to c# 3 Answers

javascript equivalent of Action? 0 Answers

convert some c# to javascript please 0 Answers

Convert Javascript to C# 1 Answer

Need help converting Javascript to C# 3 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