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 CyberArtist · Jan 02, 2015 at 04:39 PM · javascriptrotatelookat

Arm Look At script Issues (javascript)

I want to have a script that when I set weaponReady to true that the arms will aim to the center of the screen (the lookTarget game object). Unfortunately, I get this:

  1. "NullReferenceException: Object reference not set to an instance of an object" @ line 13

  2. What do I do if my script goes with no errors yet my arms won't rotate during the animation?

    var lookTarget : GameObject; var leftArm : GameObject; var rightArm : GameObject; var player : GameObject; @HideInInspector var lookRotate : float; var boneControl : GameObject;

    function Update () { if (player.GetComponent(PlayerMovement).weaponReady == true) {
    lookRotate = boneControl.transform.rotate.y.LookAt(lookTarget);

          leftArm.transform.rotate = lookRotate;
             rightArm.transform.rotate = lookRotate;
         }
     }
    
    
    
    
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jan 02, 2015 at 05:11 PM

 lookRotate = boneControl.transform.rotate.y.LookAt(lookTarget);

that line is just weird. rotate is not a member of transform. You might have meant rotation but, if you did, you wouldn't then be able to call the LookAt() method of a float variable (y).

Given that you're asking about LookAt, which is a function of the Transform component, did you mean:

 leftArm.transform.LookAt(lookTarget);
 rightArm.transform.LookAt(lookTarget);

?

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 CyberArtist · Jan 02, 2015 at 06:09 PM 0
Share

Now I get "Assets/Scripts/Control/ArmControl.js(11,42): BCE0023: No appropriate version of 'UnityEngine.Transform.LookAt' for the argument list '(UnityEngine.GameObject)' was found." For both lines.

Also I have an appropriate pose for holding the gun. I just want my arms to move up and down ai$$anonymous$$g towards the center of the screen without messing up the animation for the arms.

avatar image CyberArtist · Jan 03, 2015 at 01:58 AM 0
Share

Updated Script: var lookTarget : Transform; var cameraObject : GameObject; var leftBone : GameObject; var rightBone : GameObject; var armControl : GameObject; @HideInInspector var currentX : float;

 function Update ()
 {
     currentX = armControl.transform.rotation.x + cameraObject.GetComponent($$anonymous$$ouseLook).currentXRotation;
 }
 
 function LateUpdate () 
 {    
     if(GameObject.FindGameObjectWithTag("Player").GetComponent(Player$$anonymous$$ovement).weaponReady == true)
     {    
         armControl.transform.LookAt(lookTarget);
 
         leftBone.transform.rotate = Quaternion.Euler(currentX, 0, 0);
         rightBone.transform.rotate = Quaternion.Euler(currentX, 0, 0);
     }
 }

Getting this error: $$anonymous$$issingFieldException: UnityEngine.Transform.rotate Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateSetter () Boo.Lang.Runtime.RuntimeServices.DoCreatePropSetDispatcher (System.Object target, System.Type type, System.String name, System.Object value) Boo.Lang.Runtime.RuntimeServices.CreatePropSetDispatcher (System.Object target, System.String name, System.Object value) Boo.Lang.Runtime.RuntimeServices+c_AnonStorey19.<>m_F () Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.Dispatcher$$anonymous$$ey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) ArmControl.LateUpdate () (at Assets/Scripts/Control/ArmControl.js:20)

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

25 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

Related Questions

hoe to rotate a AI as a animation 1 Answer

LookAt Problem 1 Answer

Rotating Toward an Object at a Constant Speed 2 Answers

Help with plat-former character rotate 1 Answer

Look At objects using a SNAPPED angle 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