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 cgeopapa · Jan 25, 2015 at 05:54 PM · transformlookateuleranglescommand-line

Why nothing happens???

Hello! I have made a script that makes an empty gameObject looks at a target. Then I want the y eulerAngle rotation to be applied to an other gameObject. So the line is:

 gunBody.eulerAngles.y = aimAssist.eulerAngles.y;
 

This a Coroutine that is called from at an other line of the script... The problem is that nothing happens. The empty GameObject(aimAssist) rotates but the gunBody does nothing. Also the look at line is:

 aimAssist.LookAt(player.position);
 

Please can somebody help me??? I've tried everything I could think of!!!

Comment
Add comment · Show 2
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 meat5000 ♦ · Jan 25, 2015 at 06:49 PM 0
Share

Are you attempting to link information between two scripts?

avatar image cgeopapa · Jan 25, 2015 at 07:06 PM 0
Share

No they are both on the same script!

2 Replies

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

Answer by cgeopapa · Jan 26, 2015 at 08:59 AM

I found the problem... Looks like the way I refere to the transform of the object at the function Start was wrong:

 gunBody = GameObject.Find("GunBody").transform;
 

But, why?

Here is the whole script:

 #pragma strict
 
 //General
 var health: float;
 var playerDist: float;
 var player: Transform;
 var spoted: boolean = false;
 
 //Attack
 var gunBody: Transform;
 var gun: Transform;
 var aimAssist: Transform;
 var aimAssistRot: float;
 var rotSpeed: float;
 var canShoot: boolean = false;
 var bullet: GameObject;
 var bulletSpeed: float;
 var smoke: ParticleSystem;
 var tail: ParticleSystem;
 
 //Chase
 var agent: NavMeshAgent;
 
 function Start(){
 tail = GameObject.Find("BulletSmoke").particleSystem;
 smoke = GameObject.Find("ShootSmoke").particleSystem;
 gunBody = GameObject.Find("GunBody").transform;
 gun = GameObject.Find("Gun").transform;
 aimAssist = GameObject.Find("AimAssist").transform;
 agent = GetComponent.<NavMeshAgent>();
 }
 
 function FixedUpdate () {
 aimAssist.LookAt(player.position);
 health = GetComponent(EnemyHealth).health;
 playerDist = Vector3.Distance(player.position, transform.position);
 
 if (health > 0){
     if(playerDist < 800)
         Attack();
     else if(spoted)
         Chase();
     if(playerDist > 800 && !spoted)
         Idle();
     if(playerDist && !spoted && Time.time > 1)
         ReSpawn();
 }
 }
 
 function Attack(){
 spoted = true;
 StartCoroutine("Aim");
     if(canShoot){
         canShoot = false;
         smoke.Play();
         bullet = new GameObject("Bullet");
         bullet.AddComponent("Rigidbody");
         bullet.AddComponent("SphereCollider");
         bullet.transform.position = gun.position;
         bullet.rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
         tail.SendMessage("Attach", SendMessageOptions.DontRequireReceiver);
         bullet.AddComponent("Bullet");
         bullet.rigidbody.freezeRotation = true;
         bullet.rigidbody.velocity = gun.TransformDirection(Vector3.down * bulletSpeed);
         StartCoroutine("Reload");
     }
 }
 
 function Aim(){
 gunBody.eulerAngles.y = aimAssist.eulerAngles.y;
 //gun.eulerAngles.x = aimAssist.eulerAngles.x;
 }
 
 function Reload(){
     yield WaitForSeconds(5);
     canShoot = true;
 }
 
 function Chase(){
 agent.SetDestination(player.position);
     if(Time.time > 5)
         Lost();
 }
 
 function Lost(){
     spoted = false;
 }
 
 function Idle(){
     transform.position = transform.position;
 }
 
 function ReSpawn(){
     if(playerDist > 700)
         transform.position = new Vector3(Random.Range(0, 10000), 0, Random.Range(0, 10000));
     else
         gameObject.SetActive(true);
 }


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 Kacheek · Jan 25, 2015 at 06:11 PM

try

 gunBody.eulerAngles = new Vector3(gunBody.eulerAngles.x,aimAssist.eulerAngles.y,gunBody.eulerAngles.z);


edit: sorry i had a typing error in it ! i fixed it already

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 cgeopapa · Jan 25, 2015 at 06:44 PM 0
Share

Nothing! The same thing! I can't understand... it's like skipping the line!!

avatar image Kacheek · Jan 26, 2015 at 12:19 AM 0
Share

could you just copy paste your whole script in here ? that way we can make sure if it really is the command itself.

It could also be that you maybe put it in a if state that doesnt get true.... or maybe you've accidently put // in front of it ? or well a lot of other things could happen but this seems to be just a small mistake like a typing error or something similar

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

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

How to prevent Z axis rotation ? 1 Answer

EulerAngles value as floating point 1 Answer

LookAt transform plus a y value 1 Answer

My object isn't rotating to the transform of another object. How do I fix this? 1 Answer

Using LookAt method to get object X rotation to face another object 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