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 ayks · Oct 24, 2014 at 09:34 PM · rigidbodylagtranslationroad

rigidbody.MovePosition & translation

Hi,

I have a npc-monster which has a "road".

The part of the code :

 dir = new Vector3(10,0,10);
 for (i=0;i<100;i++){
 rigidbody.MovePosition(this.transform.position + dir * 0.01f);

and then he makes the inverse "road". But there is like some micro lags sometimes and the npc goes too far or too short so he is translated which is a problem. I tried to change all properties of rigidbody in vain.

I made a video-example : https://www.youtube.com/watch?v=QrvFO0gdDPY&feature=youtu.be

Thanks.

Comment
Add comment · Show 1
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 ayks · Nov 30, 2014 at 04:10 PM 0
Share

answer was this bug happens only when playing the game in unity editor. when the game is built (build + run) it dont happen.

1 Reply

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

Answer by M-G-Production · Dec 01, 2014 at 06:23 AM

Hi ayks!

You should read about Vector3.MoveTowards and transform.LookAt...

Actually, this is the first time I see a moving system using rigidbody.MovePosition... When you are blocked, you should try another way.

What would I do? There is a lot of ways of doing it...

  1. Create two empty objects named: Target1 and Target2 and put them where you want your monster to go;

  2. Put this in monster script:

      public GameObject target1, target2;
         public float spd;
     
         private GameObject myTarget;
     
         void Start()
         {
             myTarget = target1;
         }
         
         // Update is called once per frame
         void Update () 
         {
             if (transform.position == target1.transform.position)
             {myTarget = target2;}
     
             if (transform.position == target2.transform.position)
             {myTarget = target1;}
     
             transform.position = Vector3.MoveTowards (transform.position, myTarget.transform.position, spd * Time.deltaTime);
             transform.LookAt (myTarget.transform);
         }
    
    
  3. Drag and drop the 2 targets.

What is cool with this, you can control the speed and the destinations. If you want more than two target, read about Arrays. Don't forget that with the RigidBody component, you can add constraint with position and rotation.

This should fix these bizarre behaviors!

Math

Comment
Add comment · Show 3 · 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 ayks · Dec 01, 2014 at 12:38 PM 0
Share

Hello $$anonymous$$.G Production. Wow, a big clean answer.

I knew about transform.LookAt (basic for rpg-like :)), recently learned about Vector3.$$anonymous$$oveTowards (3-4 days ago).

I use rigidbody.$$anonymous$$ovePosition because it has to collide with player at a moment which seems logic to me although I'm not a reference of logic.

It looks cool indeed, apparently I did it without target. I think I don't like checkpoint-target, without considering efficiency. I'll keep your method for next movements things.

Thanks for the answer.

avatar image M-G-Production · Dec 02, 2014 at 10:51 PM 0
Share

Ok, I have another solution co$$anonymous$$g up for you :D

avatar image ayks · Dec 03, 2014 at 03:05 PM 1
Share

There is no more problem (with your first answer) I'm ok on this point personnally ! :y thanks :-

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

How Do I Reduce Lag in my Networked Game? 5 Answers

Does collider size affect performance? 1 Answer

Multiplayer Rigidbody Vibration 2 Answers

Why does this simple follow script make my game lag? 2 Answers

MovePosition not as precise as Translate with Kinematic rigidbodies (example unitypackage included) 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