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 potu1304 · May 25, 2017 at 02:56 PM · transform.positionlookatchild objectopencvlookattarget

Transform position of child object and look at it

Hello!

I hope the headline is not too confusing. At the moment I transform the position of a blank gameobject to use it for a LokkAt rotation. The problem is, that I do something wrong with the child object. I will simply post pictures of the hierachy. alt text

I would like to transform the LookAtRight and LookAtLeft objects with own x and y coordinates and let the shoulders look at it with LookAt. But they use them in another way I guess? If I send the x position as 140 it has a completly different position in Unity. I am very confused about this.

And here is the code where I split the strings and get the coordinates and Update the positions in Unity:

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
 public class SocketCLient : MonoBehaviour {
 
     // Use this for initialization
 
     public GameObject lefthand;
     public GameObject righthand;
     public GameObject body;
     public float xPos = 10.0f;
     public float yPos = 10.0f;
     public float ryPos = 10.0f;
     public float rxPos = 10.00f;
     private float bxPos = 0;
     private float byPos = 0;
     private String newString;
 
     Thread receiveThread;
     UdpClient client;
     public int port;
 
     //info
 
     public string lastReceivedUDPPacket = "";
     public string allReceivedUDPPackets = "";
 
     void Start () {
         init();
     }
 
     void OnGUI(){
         Rect  rectObj=new Rect (40,10,200,400);
         
         GUIStyle  style  = new GUIStyle ();
         
         style .alignment  = TextAnchor.UpperLeft;
         
         GUI .Box (rectObj,"# UDPReceive\n127.0.0.1 "+port +" #\n"
                   
                   //+ "shell> nc -u 127.0.0.1 : "+port +" \n"
                   
                   + "\nLast Packet: \n"+ lastReceivedUDPPacket
                   
                   // + "\n\nAll Messages: \n"+allReceivedUDPPackets
                   
                   ,style );
 
     }
 
     private void init(){
         print ("UPDSend.init()");
 
         port = 5065;
 
         print ("Sending to 127.0.0.1 : " + port);
 
         receiveThread = new Thread (new ThreadStart(ReceiveData));
         receiveThread.IsBackground = true;
         receiveThread.Start ();
 
     }
 
     private void ReceiveData(){
         client = new UdpClient (port);
         while (true) {
             try{
                 IPEndPoint anyIP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
                 byte[] data = client.Receive(ref anyIP);
                 string[] separators = {",", ".", "!", "?", ";", ":", " "};
                 string text = Encoding.UTF8.GetString(data);
                 // print (">> " + text);
                 lastReceivedUDPPacket=text;
                 allReceivedUDPPackets=allReceivedUDPPackets+text;
                 if (text.Contains("leftx")){
                       string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                     newString = text.Substring(5, 3);
                     xPos = int.Parse(words[1]);
                     print(xPos);
                 }
                 if (text.Contains("lefty")){
                     string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                     yPos = int.Parse(words[1]);
                     newString = text.Substring(5, 3);
                     // yPos = int.Parse(newString);
                     // print("yPos: ");
                     // print(yPos);
                     // if (yPos > 140)
                     //     yPos = -yPos;
                 }
                 if (text.Contains("bodyx")){
                     string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                     bxPos = int.Parse(words[1]);
                     newString = text.Substring(5, 3);
                     // bxPos = int.Parse(newString);
                 }
                 if (text.Contains("bodyy")){
                     string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                     byPos = int.Parse(words[1]);
                     newString = text.Substring(5, 3);
                     // byPos = int.Parse(newString);
                 }
                 if (text.Contains("righty")){
                     string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                     ryPos = int.Parse(words[1]);
                     newString = text.Substring(6, 3);
                     // ryPos = int.Parse(newString);
                 }
                 if (text.Contains("rightx")){
                     string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                     rxPos = int.Parse(words[1]);
                     newString = text.Substring(6, 3);
                     // rxPos = int.Parse(newString);
 
                 }
                 //xPos = int.Parse(text);
                 //xPos *= 0.021818f;
             }catch(Exception e){
                 // print (e.ToString());
             }
         }
     }
 
     public string getLatestUDPPacket(){
         allReceivedUDPPackets = "";
         return lastReceivedUDPPacket;
     }
     
     // Update is called once per frame
     void Update () {
 
         // print("xPos " + xPos.ToString());
         // print("rxPos " + rxPos.ToString());
         body.transform.position = new Vector3(bxPos, byPos);
         lefthand.transform.position = new Vector3(xPos, -yPos);
         righthand.transform.position = new Vector3(-rxPos, -ryPos);
         print("rxPos: " + rxPos.ToString() + " ryPos: " + ryPos.ToString());
         // if(yPos < byPos)
         //     lefthand.transform.position = new Vector3(xPos, yPos , 0);
         // if(yPos > byPos)
         //     lefthand.transform.position = new Vector3(xPos, yPos , 0);    
         //lefthand.transform.Rotate(0, yPos,  -10, Space.World);
     }
 
     void OnApplicationQuit(){
         if (receiveThread != null) {
             receiveThread.Abort();
             Debug.Log(receiveThread.IsAlive); //must be false
         }
     }
 }
1.png (335.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

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

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

Related Questions

How to make AI look at player 0 Answers

Look at is zooming out 0 Answers

How to make an object "LookAt" a target rotating around, but keep its current orientation 2 Answers

How to rotate towards a target but only on the y axis ? 1 Answer

What is the best way to let a character follow a moving object with his head 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