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 jvcraft87 · Feb 06, 2013 at 10:07 PM · androidtransform.positionjoystick

transform.position problem

Hi,

I have an empty game object with the following script attached:

 using UnityEngine;
 using System.Collections;
 
 public class GameMaster : MonoBehaviour {
     
     public GameObject playerCharacter;
     
     private GameObject _pc;
     
     private Vector3 _playerSpawnPos;
 
     void Start () {
         
         _playerSpawnPos = new Vector3(20.0f, 4.0f, 20.0f);
         
         //_pc = Instantiate( playerCharacter, _playerSpawnPos, Quaternion.identity ) as GameObject;
         _pc = Instantiate( playerCharacter, Vector3.zero, Quaternion.identity ) as GameObject;
         
         _pc.name = "wtf";    
         
         _pc.transform.position = _playerSpawnPos;
     }
 }

I have a prefab based on the Camera Relative Controls controller. This prefab becomes my "playerCharacter" Game Object. When I transform the position the joysticks show up at (-20, -4, 0). So they aren't showing up in the camera. The capsule and the camera transform ok, just not the joysticks. What am I missing?

Thanks for any help!!

Cheers!

Jim

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 Dave-Carlile · Feb 08, 2013 at 05:13 PM 0
Share

Don't see anything about joysticks on your code? I assume this is another game object? Is it a child object in the prefab? Any child objects are going to be repositioned relative to the parent when you transform.

avatar image jvcraft87 · Feb 10, 2013 at 11:53 PM 0
Share

Hi Dave,

The joysticks are part of the Standard Assets ($$anonymous$$obile) Camera Relative Control prefab. I place that prefab into the Public GameObject playerCharacter. I'm just utilizing the prefab to get some control elements in my view, but as I mention they aren't showing up.

Jim

avatar image DaveA · Feb 11, 2013 at 12:02 AM 0
Share

I'm not sure I follow that, but you don't want to put the joysticks component in another object that itself might move around.

avatar image jvcraft87 · Feb 11, 2013 at 12:13 AM 0
Share

This control is devised to use the joysticks for character movement on a mobile device. Admittedly I could be misunderstanding how Unity meant it to be used and perhaps I should be moving a child object rather than the parent. The prefab has the following hierarchy:

Camera Relative Controls - Camera Relative Controls - - Camera Pivot - - - Camera Offset - - - - Camera - - Player - - - ReplaceWithRealCharacter - Left Joystick - Right Joystick

Perhaps I should be applying the movement to the second tier Camera Relative Controls?

avatar image jvcraft87 · Feb 11, 2013 at 12:33 AM 0
Share

Well that sucked ... Try a different approach ... The hierarchy of the prefab is:

 Camera Relative Controls
 - Camera Relative Controls
 - - Camera Pivot
 - - - Camera Offset
 - - - - Camera
 - - Player
 - - - ReplaceWithRealCharacter
 - Left Joystick
 - Right Joystick

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jvcraft87 · Feb 12, 2013 at 10:33 PM

DaveA,

You were correct in that I shouldn't be moving the joysticks. Thanks for that pointer!

So the corrected code is:

 using UnityEngine;
 using System.Collections;
  
 public class GameMaster : MonoBehaviour {
  
     public GameObject playerCharacter;
  
     private GameObject _pc;
  
     private Vector3 _playerSpawnPos;
  
     void Start () {
  
        _playerSpawnPos = new Vector3(20.0f, 4.0f, 20.0f);
  
        _pc = Instantiate( playerCharacter, Vector3.zero, Quaternion.identity ) as GameObject;
  
        _pc.name = "wtf"; 
  
        _pc.transform.Find("Camera Relative Controls").position = _playerSpawnPos;
     }
 }

So I basically find the child that holds the player character and the camera (this child is at the same level as the Joysticks), and transform the position of that child. Voila!

Again, thanks for the pointer DaveA!

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

11 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

Related Questions

Moving Joysticks 0 Answers

Android Gamepad/joystick mapping? 0 Answers

How to make an android joystick like Arcane Legends 0 Answers

How to control a 2d character in an top-down android game with the standard joystick? 1 Answer

Unity 4, Multitouch/FingerId and Android 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