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 LightSource · Mar 18, 2013 at 10:05 PM · javascriptmovementinputtranslate

Translating Object Continually

Problem:

Only translates when "F" key is held.

Question:

How can I press once and have it continue moving?

Script:

 var force : float = 20.0f;
 var spawnDistance : float = 1.0f;
 var gameObject : GameObject;
 
 function Start() {
 
 if(Input.GetKey(KeyCode.F)) {
 
     GameObject.Instatiate(transform.position + spawnDistance * transform.forward, transform.rotation);
     
     rigidbody.AddForce(transform.forward * force);
 }
 }
Comment
Add comment · Show 3
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 AlucardJay · Mar 19, 2013 at 04:09 AM 1
Share

in your current form, line 9 should be :

 gameObject = Instantiate( RE$$anonymous$$OVED FOR COUGH COUGH REASONS );

but this variable name is a big no-no. Unity uses both these names as key words (gameObject and GameObject), even if you look at any Unity Scripting Reference for Instantiate or Create, they use the variable name 'go'. Basically, don't use any Unity keyword as a variable name. It's not hard to call it 'myGameObject' or simply 'go' as in the docs.

EDIT : Note the spelling error in your Instantiate also. It is up to you to proofread your code and check for spelling and syntax errors

avatar image Fattie · Mar 19, 2013 at 08:02 AM 1
Share

a good name would be "awesomeGameObject"

avatar image AlucardJay · Mar 19, 2013 at 12:31 PM 0
Share

Indeed! You have an awesome flair for na$$anonymous$$g conventions.

1 Reply

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

Answer by DaveA · Mar 18, 2013 at 10:26 PM

Change 'Start' to 'Update'

Comment
Add comment · Show 9 · 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 LightSource · Mar 18, 2013 at 10:44 PM 0
Share

Nope I get this: $$anonymous$$issing$$anonymous$$ethodException: $$anonymous$$ethod not found: 'UnityEngine.GameObject.Instatiate'.

I changed it back to start and now it wont work at all. $$anonymous$$gestions?

avatar image Eric5h5 · Mar 19, 2013 at 04:23 AM 1
Share

There's no function called "Instatiate", as the error says. Watch the typos, program$$anonymous$$g is an exact science (also make use of syntax coloring, which helps you notice typos easier). Also you need Get$$anonymous$$eyDown, which fires once, not Get$$anonymous$$ey, which fires every frame.

avatar image LightSource · Mar 19, 2013 at 06:53 PM 0
Share

$$anonymous$$y new script with this error; I thought unity had Instatiate as a component?

 $$anonymous$$ identifier: 'Instatiate'.

 var force : float = 20.0f;
 var spawnDistance : float = 1.0f;
 var awesomeGameObeject : GameObject;
 
 function Update() {
 
 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.F)) {
 
     awesomeGameObeject = Instatiate(transform.position + spawnDistance * transform.forward, transform.rotation);
     
     rigidbody.AddForce(transform.forward * force);
 }
 }
avatar image Eric5h5 · Mar 19, 2013 at 06:55 PM 0
Share

You really need to spell Instantiate correctly....

avatar image roojerry · Mar 19, 2013 at 07:08 PM 1
Share

You are missing the first argument of Object.Instantiate. You need a GameObject to instantiate at that position and rotation

see Object.Instantiate

Show more comments

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

15 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

Related Questions

My controls are inverted when facing sideways. 1 Answer

Object keeps orbiting target location in a Coroutine 0 Answers

how to move an object in 2D sense its position? 0 Answers

PLEASE help me to translate this javascript to C# for my VS10 application 1 Answer

Using Rigidbody.MovePosition With Local Position and Lerp 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