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 DolphinDudeOne · Jul 12, 2014 at 03:34 AM · javascriptrigidbodyaddforcevar

Declaring myRigidbody

I so far have this script to make my monster move but it says that there is an unknown identifier "myRigidbody".

 #pragma strict
 
 var target : Transform;
 var moveSpeed = 240;
 var rotationSpeed = 180;
 var myTransform : Transform;
 
 function Awake()
 {
     myTransform = transform;
 }
  
 function Start()
 {
     target = GameObject.FindWithTag("Player").transform;
     
 }
  
 function Update () {
 
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
  
     myRigidbody.AddForce(myTransform.forward * moveSpeed * Time.deltaTime);
      
 }

Could somebody show me how to identify it or where I went wrong scripting.

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
Best Answer

Answer by robertbu · Jul 12, 2014 at 03:38 AM

If you double click on the error in the console, it will take you to the error. In this case it is on line 24. You have not declared 'myRigidbody'. You can use 'rigidbody' instead. Rigidbody is a shortcut that under the hood it is equivalent to:

GetComponent(Rigidbody);

Note you can avoid the GetComponent() call every time you use it by doing the same thing that you did with myTransform. That is declare at the top of the file at line 7:

 var myRigidbody : Rigidbody;

And then in Start() do:

 myRigidbody = rigidbody;

Then line 24 will work unchanged.

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 DolphinDudeOne · Jul 12, 2014 at 03:47 AM 0
Share

Thanks! The script plays now!

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

2 People are following this question.

avatar image avatar image

Related Questions

AddForce not working 0 Answers

Using "Tag" to disable Rigidbody Constraints 1 Answer

How do I add force in the on trigger 1 Answer

How do I add force on an object(with a rigidbody) that I've randomly instantiated along the "Y" axis? 2 Answers

rigidbody.AddForce to another object 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