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 dail · Feb 04, 2015 at 01:23 PM · 2dgameobjectarray

Gameobject follow between array of gameobjects

Hello guys. I have a doubt in my code that doesn't work. I'm trying to get my cube follow the path between an array of gameobjects with a variable to control the speed of the cube and jump when it is requested. If anyone can help!.My code:

  void Update()
     {
       
  
 target.position = new Vector3(path[c].position.x, path[c].position.y + 1f, path[c].transform.position.z);
             if (target.position.z >= path[c].position.z)
             {
                 if (c < path.Length)
                     c++;
             }
             target.LookAt(path[c]);
 
             if (Input.GetKey(KeyCode.UpArrow))
             {
                 rigidbody2D.AddForce(target.forward * speed2);
             }
 }


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 IvovdMarel · Feb 05, 2015 at 12:31 AM

If you want to make it stop when it's close to the target, you can use Vector3.Distance (and check if it's smaller than a certain amount).

If you call AddForce every frame, more and more force will be applied and the object will most likely accelerate really fast. Instead, directly set the velocity by using rigidbod2D.velocity.

Comment
Add comment · Show 6 · 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 dail · Feb 05, 2015 at 12:49 AM 0
Share

$$anonymous$$y problem is that I have an array of 242 gameobjects. $$anonymous$$y cube until moves between the path but it passes very, very fast. I want to control this speed

avatar image IvovdMarel · Feb 05, 2015 at 01:01 AM 0
Share

As I said: directly set the velocity ins$$anonymous$$d of using AddForce

avatar image dail · Feb 05, 2015 at 01:07 AM 0
Share

AddForce is only called when the button is pressed. I say in the constant movement of the cube that is too fast. He goes through each node very fast. I've used velocity in Update() but it didn't work

avatar image IvovdMarel · Feb 05, 2015 at 01:10 AM 0
Share

So isn't the idea that you hold the key to make the object move?

 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.UpArrow))
                  {
                      rigidbody2D.velocity = target.forward * speed2;
                  } else {
           rigidbody2D.velocity = Vector3.zero;
     }





avatar image dail · Feb 05, 2015 at 01:22 AM 0
Share

Sorry if that didn't come out right. The cube will move infinitely, but it's movement is too fast. This snippet: if (Input. Get$$anonymous$$ey ($$anonymous$$eyCode. UpArrow)) is a leap that the cube only makes. So, it's not my problem

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D gameobject array coordinates 1 Answer

Instantiating a gameObject in an array is not working for me 1 Answer

2D Array of GameObjects... 1 Answer

2D array of GameObjects C# 2 Answers

2D GameObject Array to 2D List 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