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 trinitysj96 · Jan 11, 2013 at 07:06 PM · cameraainpc3dtext

3d text backwards when facing camera

I am new to this forum but have been using Unity for a while now. I have made alot of progress with the game I am working on so far but am having a hangup on this one piece.

 var Enemy: Transform;
 var distance = 5;
 var Explode : Transform;
 var circle : Transform;
 var projectile : Rigidbody;
 //sounds for attacking
 var SmiteSound: AudioClip;
 //background texture
 var attack : Texture2D;
 var smite : Texture2D;
 //textures for buttons
 var xout : Texture2D;
 var wasClicked: boolean = false;
 //arrow shooting
 var speed = 5.0;
 var rotateSpeed = 3.0;
 //health
 var DamageNumber : int; 
 var hp = 100.0;
 var HitPoints = 100.0;
 var ScorePoints = 2.0;
 var track_speed : float = 2;
 var look_at : Quaternion;
 var enemies_list = new GameObject[10];
 var aiming_at : int = 0;
 var aiming : boolean = false;
 
 var cameraToUse : Camera;
 var SetPlayerName : String;
 var TextMeshName : GameObject;
 
 var style : GUIStyle;
     
 //selection circle disabled
 circle.renderer.enabled = false;
 aiming = false;
 
 
 function Start(){
     style.normal.textColor = Color.yellow;
     style.fontSize = 15;
 
     DamageNumber = Random.Range(1,(HitPoints/6));
 }
 
 function OnMouseUp() {
     wasClicked = true; // turns on button.
     circle.renderer.enabled = true;
     
     if(aiming == false)
         {
         update_list();
         if (enemies_list.length > 0) // If we don't have enemies, we don't need to do the quaternion code
             aiming = false;    //  for performance reasons.
         }
 }
 
 function OnGUI() {
           
     GUI.depth = 50;
     if (wasClicked) {
         wasClicked=true;
         //show inventory bar
            
            GUI.BeginGroup (Rect (Screen.width / 2 - 450, Screen.height - 49, 900, 49));
             
             if(GUI.Button (Rect (43,8,39,40), attack, GUIStyle.none)){
                 //BuffPlate.active=true;
                 audio.PlayOneShot(SmiteSound);
             
                 //instantiate the projectile
                 var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation); 
             
                 //move the projectile 
                 instantiatedProjectile.velocity = (enemies_list[aiming_at].GetComponent(Transform).position - transform.position)*speed;
                 Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);     
 
                    DamageNumber = Random.Range(1,(HitPoints/6));
                 print ("hit : " + aiming_at + " with " + DamageNumber + " damage");
                 hp = hp -= DamageNumber;
                 Destroy(instantiatedProjectile.gameObject, 5); 
 
             } 
             if(GUI.Button (Rect (79,8,39,40), smite,GUIStyle.none)){
                    
             } 
             
             if (GUI.Button(new Rect(408, 8, 39, 40), xout,GUIStyle.none)) {
                 circle.renderer.enabled = false;
                 wasClicked = false; // turns off button.
             }
         
             GUI.EndGroup ();
     }
 }
 
 function Update(){
     
     SetPlayerName = Enemy.name;
     TextMeshName.gameObject.GetComponent(TextMesh).text = SetPlayerName + "\n\r" + hp;
         
     if (Input.GetKeyDown("1")) {
         if (wasClicked) {
             wasClicked=true;
             audio.PlayOneShot(SmiteSound);
             
             //instantiate the projectile
             var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation); 
             
             //move the projectile 
             instantiatedProjectile.velocity = (enemies_list[aiming_at].GetComponent(Transform).position - transform.position)*speed;
             
             Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider); 
             
             // Send a damage message to the hit object          
             DamageNumber = Random.Range(1,(HitPoints/6));
             print ("hit : " + aiming_at + " with " + DamageNumber + " damage");
             hp = hp -= DamageNumber;
             Destroy(instantiatedProjectile.gameObject, ScorePoints); 
             
             //print ("aiming at : "+aiming_at);
             }
        }
     
     if(aiming == true)
     {    
     
     look_at = Quaternion.LookRotation(enemies_list[aiming_at].GetComponent(Transform).position - transform.position);
     look_at.x = 0;
     look_at.z = 0;
     transform.rotation = Quaternion.Lerp(transform.rotation, look_at, track_speed);
     // This will make the character turn to the enemy
     
     // The next part handles the switching between enemies
     if (Input.GetKeyDown("-"))
         {
         if (aiming_at < enemies_list.length) 
             aiming_at++;
             
         else
             aiming_at = 0; 
         }
     
     if (Input.GetKeyDown("="))
         {
         if (aiming_at > 0)
             aiming_at--;
     
         else                                                 
             aiming_at = enemies_list.length -1;
         }
     }
      
     if (hp <= 0)
     Destroy(gameObject);
     
     if (hp <= 0)
     {
         print ("scores: " + PlayerPrefs.GetString("playerName") + "--" + ScorePoints);
         //Instantiate(Explode, transform.position, transform.rotation);
         
         postScore(PlayerPrefs.GetString("playerName"),ScorePoints);    
     }
 }
 function update_list(){
         enemies_list = GameObject.FindGameObjectsWithTag("Enemy");
 }
 
 function postScore(name, score) {
     //var hash=Md5.Md5Sum(name + score + secretKey); 
  
     var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score;
  
     // Post the URL to the site and create a download object to get the result.
     hs_post = WWW(highscore_url);
     yield hs_post; // Wait until the download is done
     if(hs_post.error) {
         print("There was an error posting the high score: " + hs_post.error);
     }
 }
         
 @script RequireComponent(AudioSource)

This piece of code allows me to select the NPC, show the attack buttons, and calculate the death, then destroy and update scoring.

the problem is that the 3d text is backwards and not facing the camera. I did use the CameraFacingBillboard.cs example HERE and now the 3d text faces the camera as I walk around the NPC. However, the text is backwards and I cannot figure out how to flip it around. I am also using Unity 4 and a lot of the examples that I see are for Unity 3. Does this make a difference when doing the scripting?

the specific place the name of the NPC is placed is the first two lines of the update function.

 SetPlayerName = Enemy.name;
 TextMeshName.gameObject.GetComponent(TextMesh).text = SetPlayerName + "\n\r" + hp;

I have tried to do several examples and nothing seems to work, or breaks the code. Can anyone help?

Thanks.

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 Wolfram · Jan 12, 2013 at 12:41 AM 0
Share

Where is the relevant part in your script dump that uses 3D text and/or the billboard? Don't just dump tons of code on us that are unrelated or irrelevant.

avatar image trinitysj96 · Jan 12, 2013 at 01:59 AM 0
Share

the part that says:

SetPlayerName = Enemy.name; Text$$anonymous$$eshName.gameObject.GetComponent(Text$$anonymous$$esh).text = SetPlayerName + "\n\r" + hp;

that is the 3d text portion. I included the whole script to show what I was doing in total.

avatar image Wolfram · Jan 12, 2013 at 02:04 AM 0
Share

Ah, didn't realise these two lines were part of that script. Have you tried my answer?

avatar image trinitysj96 · Jan 12, 2013 at 02:12 AM 0
Share

yes I did and that worked.

avatar image Wolfram · Jan 12, 2013 at 02:15 AM 0
Share

Glad to hear!

2 Replies

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

Answer by Wolfram · Jan 12, 2013 at 12:41 AM

Replace Vector3.back in your CameraFacingBillboard script with Vector3.forward (assuming you're using the non-modded version).

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 trinitysj96 · Jan 12, 2013 at 02:13 AM 0
Share

thanks for at. That worked like a charm... Now to change the color of the 3d text...

avatar image Wolfram · Jan 12, 2013 at 03:18 PM 0
Share

For reference: this is not a clean solution, but the quickest solution. However, you might run into similar problems if you now want to use the billboard script for other objects (e.g., Unity planes, other objects).

The root of the problem is that the billboard script has to pick one axis and orient that towards the camera. Generally that should be the local +Z axis of the object, as this is generally considered the "forward" axis of an object in Unity. If the object doesn't adhere to that convention (as the 3D text probably doesn't), you'd either have to pivot your object correctly first (i.e., attach the script to the parent of your object, then locally rotate your object to make it align along +Z of the parent) - or you could use the "hack" I provided, which works for this special case.

avatar image
0

Answer by Julien-Lynge · Jan 11, 2013 at 07:09 PM

There's no difference between Unity 3 and Unity 4 with this kind of scripting. Most likely you'll have to modify the CameraFacingBillboard script to rotate the text 180 degrees around the Y axis. Take a look at the Transform script reference - there are a couple ways to rotate objects, and there is example code for each.

http://docs.unity3d.com/Documentation/ScriptReference/Transform.html

Comment
Add comment · Show 1 · 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 trinitysj96 · Jan 11, 2013 at 11:47 PM 0
Share

thanks for noting that there is no differece between the versions. that is good to know... I am trying to get this figured out.. and the docs arent helping me at the moment. Still working on it though.

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

10 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

Related Questions

Helper AI follow character 0 Answers

How do I animate an 'enemy' NPC? 0 Answers

Issues NPC Grenade avoidance 3 Answers

Can unity3d combined with Artificial Intelligent or Soft Computing? 3 Answers

Simple airplane AI 2 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