Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TsomoNe · Apr 01, 2016 at 06:15 AM · move object

How to move object when click on specific tile?

I want to move polygon object (cube, triangle, etc) when i click on specific tile of the object. How to do?

![example][1]

img-20160401-135217.jpg (162.9 kB)
img-20160401-135217.jpg (162.9 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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ShadoX · Apr 01, 2016 at 06:21 AM

Try taking a look at http://answers.unity3d.com/questions/128747/detect-face-of-cube-clicked.html

Think a "simple" way to do it would be to: 1) detect which face was clicked and get the coordinates of it (x,y,z) 2) compare the coordinates to the center coordinates of the cube and use that to figure out which way the cube should start moving * can use static values for moving it by 1 block or probably just get the side from the cube object itself and then just move it 1 unit forward

Hope this helps in some way :)

Comment
Add comment · Show 2 · 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 TsomoNe · Apr 01, 2016 at 07:02 AM 0
Share

Thank you, i'm a absolute beginner for Unity3D game development. I will try it then give you respond ASAP. Sorry for my english. Thank you again :)

avatar image TsomoNe · Apr 15, 2016 at 08:02 AM 0
Share

@ShadoX i tested your suggestion. it works for detect face of objects. But when i rotate object by 90 degrees. it gives me same result.

Example: Before rotation: result of cube is South, Up, East ... After rotation: result of cube is South, Up, East...

What i want is: Before rotation: result of cube is South, Up, East ... After rotation: result of rotated cube like (if 90 degree rotated East, Up, North)

Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class SideDetecter : $$anonymous$$onoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
 
     public float speed = 50f;
 
     public Transform gunObj;
     // Update is called once per frame
     void Update () {
         if (Input.Get$$anonymous$$ouseButton(0)) {
             //transform.RotateAround(Vector3.zero, Vector3.up, speed * Time.deltaTime);
 
             //Debug.Log ("$$anonymous$$ouse Clicked");
             RaycastHit hit;
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out hit)) {
                 Debug.Log ("RayCast");
                 Vector3 inco$$anonymous$$gVec = hit.point - gunObj.position;
                 Vector3 reflectVec = Vector3.Reflect(inco$$anonymous$$gVec, hit.normal);
                 Debug.DrawLine(gunObj.position, hit.point, Color.red);
                 Debug.DrawRay(hit.point, reflectVec, Color.green);
             }
             //transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;    
             GetHitFace(hit);
         }
     }
 
     public enum $$anonymous$$CFace
     {
         None,
         Up,
         Down,
         East,
         West,
         North,
         South
     }
 
     public $$anonymous$$CFace GetHitFace(RaycastHit hit)
     {
         Debug.Log ("RayCast2");
         Vector3 inco$$anonymous$$gVec = hit.normal - Vector3.up;
 
         if (inco$$anonymous$$gVec == new Vector3(0, -1, -1)) {
             Debug.Log ("$$anonymous$$CFace.South");
             return $$anonymous$$CFace.South;
         }
 
         if (inco$$anonymous$$gVec == new Vector3(0, -1, 1)) {
             Debug.Log ("$$anonymous$$CFace.North");
             return $$anonymous$$CFace.North;
         }
 
         if (inco$$anonymous$$gVec == new Vector3(0, 0, 0)) {
             Debug.Log ("$$anonymous$$CFace.Up");
             return $$anonymous$$CFace.Up;
         }
 
         if (inco$$anonymous$$gVec == new Vector3(1, 1, 1)) {
             Debug.Log ("$$anonymous$$CFace.Down");
             return $$anonymous$$CFace.Down;
         }
 
         if (inco$$anonymous$$gVec == new Vector3(-1, -1, 0)) {
             Debug.Log ("$$anonymous$$CFace.West");
             return $$anonymous$$CFace.West;
         }
 
         if (inco$$anonymous$$gVec == new Vector3(1, -1, 0)) {
             Debug.Log ("$$anonymous$$CFace.East");
             return $$anonymous$$CFace.East;
         }
 
         return $$anonymous$$CFace.None;
     }
 }
 
avatar image
0

Answer by AliSOft · Oct 04, 2017 at 08:04 AM

The following code has worked for me.

 TransparentObject.transform.position = hit.transform.position + hit.normal;
 TransparentObject.transform.rotation = hit.transform.rotation;

Let me know if it worked for you or not.

Comment
Add comment · 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
0

Answer by xPro-Gamerx · Jul 24, 2021 at 10:27 AM

 // Start is called before the first frame update  
 void Start()  
 {  
       
 }  
  
 // Update is called once per frame  
 void Update()  
 {  
     if (Input.GetKey(KeyCode.A))  
     {  
         transform.Translate(0.1f, 0f, 0f);  
     }  
     if (Input.GetKey(KeyCode.D))  
     {  
         transform.Translate(-0.1f, 0f, 0f);  
     }  
     if (Input.GetKey(KeyCode.S))  
     {  
         transform.Translate(0.0f, 0f, -0.1f);  
     }  
     if (Input.GetKey(KeyCode.W))  
     {  
         transform.Translate(0.0f, 0f, 0.1f);  
     }  
 }  

}

this is the way to move

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Moving object away from newly created object created by script 0 Answers

Move object from A to B around Zero 1 Answer

Problem with player bouncing or jumping 1 Answer

Make object move (not teleport) to another object 1 Answer

Moving an object along one axis based on the position of a different object 0 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