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 /
This question was closed Dec 04, 2014 at 05:11 AM by Prasanna for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Prasanna · Mar 20, 2014 at 06:15 AM · c#rotateboardgameedges

Finding Edges

Hello there, i want know how to find edge for an object manually using script(C#). Basically i have created board using script, here i need know the edges for the Board.

Camera position is: Transform.position.x = 5; Transform.position.y = 13; Transform.position.z = -7.5;

Camera rotation is: Transform.rotation.x = 45;

Here is the coding...

using UnityEngine; using System.Collections;

[ExecuteInEditMode] [RequireComponent(typeof(MeshFilter))] [RequireComponent(typeof(MeshRenderer))] [RequireComponent(typeof(MeshCollider))]

public class Board : MonoBehaviour

{

 // Board Creation Variables/....
 public static int size_x=10;
 public static int size_z=10;
 public static float tileSize=1.0f;


 // Use this for initialization
 void Start () 
 {
     CreateBoard();
 }


 // Board Creation/.....
 public void CreateBoard()
 {
     int numTiles        =    size_x * size_z;
     int numTris            =    numTiles * 2;

     int vsize_x            =    size_x + 1;
     int vsize_z            =    size_z + 1;
     int numVerts        =    vsize_x * vsize_z;

     Vector3[] vertices    =    new Vector3[numVerts];
     Vector3[] normals    =    new Vector3[numVerts];
     Vector2[] uv        =    new Vector2[numVerts];

     int[] triangles        =    new int[numTris*3];

     int x,z;
     for(z=0; z < vsize_z; z++)
     {
         for(x=0 ; x < vsize_x; x++)
         {
             vertices[ z * vsize_x + x]=new Vector3(x * tileSize, 0 , z*tileSize);
             normals[z * vsize_x + x]=Vector3.up;
             uv[z * vsize_x + x]=new Vector2((float)x / size_x,(float)z / size_z);
         }
     }

     for(z=0; z < size_z; z++)
     {
         for(x=0 ;x < size_x; x++)
         {
             int squareIndex    =    z * size_x + x;
             int trioffset    =    squareIndex * 6;
             triangles[trioffset + 0]    =    z * vsize_x + x + 0;
             triangles[trioffset + 2]    =    z * vsize_x + x + vsize_x + 1;
             triangles[trioffset + 1]    =    z * vsize_x + x + vsize_x + 0;

             triangles[trioffset + 3]    =    z * vsize_x + x + 0;
             triangles[trioffset + 5]    =    z * vsize_x + x + 1;
             triangles[trioffset + 4]    =    z * vsize_x + x + vsize_x + 1;
         }
     }

     Mesh mesh    =    new Mesh();
     mesh.vertices    =    vertices;
     mesh.triangles    =    triangles;
     mesh.normals    =    normals;
     mesh.uv        =    uv;

     MeshFilter mesh_filter        =    GetComponent<MeshFilter>();
     MeshRenderer mesh_renderer    =    GetComponent<MeshRenderer>();
     MeshCollider mesh_collider    =    GetComponent<MeshCollider>();

     mesh_collider.sharedMesh = mesh;
     mesh_filter.mesh    =    mesh;
 }

}

i also attached my Texture image. Here is my problem my character moving towards the number 1,2,3,4..., if he reach number 10 in the board he need to rotate himself to 90 degree up. So for that i need to know how to calculate the edge of the border without using triggers.

any help will be appreciated

-Prasanna.

board_upper.png (99.4 kB)
Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Berenger · Mar 20, 2014 at 09:10 AM

Does your character knows what tile it's on ? Because you could calculate if the tile on the edge or not with something like :

 if( currentTile % size_x == 0 || (currentTile-1) % size_x == 0
     || currentTile < size_x || currentTile >  size_x * (size_x-1) )
     ...
Comment
Add comment · Show 4 · 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 Prasanna · Mar 20, 2014 at 01:03 PM 0
Share

No my character don't know, but i used something like this:

using UnityEngine; using System.Collections;

public class Character$$anonymous$$ovement : $$anonymous$$onoBehaviour

{ // Player $$anonymous$$ovement Variables/....

 public static int  $$anonymous$$yPosition, NextPositionValue;
 public static float $$anonymous$$oveSpeed = 0.5f, CurrentTile = 0.5f, NextTile, EdgeTile, StartTile, EdgePositionValue, Edge;
 public static bool Condition = false, Clicked = false;
 public static Vector3 StartPosition, CurrentPosition, PreviousPosition, NextPosition, NewPosition, EdgePosition;


 public void Border()
 {
     // Create a Border for 10th value...

 }

 public void Update()
 {
     if(Clicked == true)
     {
         Edge                =    3.5f;
         StartPosition         =     this.transform.position;
         CurrentPosition     =     StartPosition;
         NextTile             =     CurrentTile + Dice.value;
         EdgeTile            =    CurrentTile + Edge;
         $$anonymous$$yPosition             =     (int)this.transform.position.x;
         NextPositionValue     =     $$anonymous$$yPosition + Dice.value;
         NextPosition         =     CurrentPosition + new Vector3(Dice.value,0,0);
         EdgePosition        =    CurrentPosition + new Vector3(Edge, 0, 0);
         Clicked             =     false;
     }
     if(CurrentPosition.x < NextPosition.x)
     {
         if(Condition == true)
         {
             animation.Play("Walk");
             transform.Translate(Vector3.forward * $$anonymous$$oveSpeed * Time.deltaTime);
         }
     }
     
     if(this.transform.position.x >= NextPosition.x)
     {
         Condition = false;
         animation.Play("Idle");
     }
     if(this.transform.position.x == EdgePosition.x)
     {
         Debug.Log("Enter");
     }

     if(Ladder15.trigger == true)
     {
         transform.Rotate (new Vector3 (0, 90, 0) * Time.deltaTime);
     }
 }

}

this is for character movement. Here i used to find the edge, but i can't.

avatar image Berenger · Mar 20, 2014 at 01:28 PM 0
Share

If you start at 1, you can know the index of the tile. A dice value positive means +1, negative means -1.

By the way, you should take a look at iTween for the translation, that would probably make it cooler ;)

avatar image Prasanna · Mar 21, 2014 at 07:27 AM 0
Share

I tried iTween for rotation using trigger, my case the trigger won't work. In my Character$$anonymous$$ovement script i have added the edge variables, i declare the edge is 3.5f; but it doesn't work. Where can i find the edge, in Chareacter$$anonymous$$ovement script or Board script.

avatar image Prasanna · Mar 21, 2014 at 07:31 AM 0
Share

So the basic thing what i want to know if my character stand the edge(10th Box). Character need to turn himself to 90 degree up, i already added my scripts for Board and Character$$anonymous$$ovement. What i did in Character $$anonymous$$ovement script i try ti find the edge, but i can't get that.

-Prasanna

board_upper.png (99.4 kB)

Follow this Question

Answers Answers and Comments

21 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 avatar image avatar image

Related Questions

Rotating Cuboid Around Pivot 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

C# Rotate More than Two GameObjects 1 Answer

A node in a childnode? 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