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 Paparakas · Oct 29, 2013 at 05:42 PM · rigidbodyoptimizationlag

Why does this simple follow script make my game lag?

It makes my game lag when I apply it to an object. All it's supposed to do is follow my character without modifying the y position so it always stays on the ground. If it collides with my character then my character loses 1 hitpoint. Here's a screen shot of the settings for the rigidbody and other components of the enemy that I applied this script to. http://i.imgur.com/yDpFhAG.png?1 The little crab like things are what the enemy looks like.

It looks like it I remove transform.LookAt(Player.transform.position); it stops lagging. Does anyone know why?

NEW FINDING Changing collision detection to discrete also makes the problem go away, even in the presence of transform.LookAt.

 public float Speed;
 
     void Start () {
        Player = GameObject.FindWithTag("Player");
        transform.LookAt(Player.transform.position);
     }
  
     void FixedUpdate()
     {
          SeekTarget();
     }
 
     void SeekTarget()
 
     {
        Vector3 MoveTowardsPosition = Vector3.MoveTowards(transform.position,Player.transform.position, Speed * Time.deltaTime);
        MoveTowardsPosition.y = transform.position.y;
        rigidbody.MovePosition(MoveTowardsPosition);
 
        transform.LookAt(Player.transform.position);
     }
Comment
Add comment · Show 11
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 Paparakas · Oct 30, 2013 at 03:10 PM 0
Share

Anyone? Is there nothing in this script that raises a red flag?

avatar image tanoshimi · Oct 30, 2013 at 03:22 PM 0
Share

When you say "lag", you mean becomes less responsive to player input? Or that the frame rate drops? (by how much?) Is this the only script? How many crab objects do you have it attached to?

avatar image Paparakas · Oct 30, 2013 at 05:06 PM 0
Share

@tanoshimi The framerate drops. I have 3 crab objects. I've just noticed that the lag only happens when the crabs are near each other. When they are, it varies from 2-10 and then back to 60fps. If I delete 1 crab and only 2 of them are near each other, I don't experience the fps drop. I recorded a video of what happens here: http://www.youtube.com/watch?v=B44nlRaOGPE&feature=youtu.be

avatar image Paparakas · Oct 30, 2013 at 05:35 PM 0
Share

Here's a screenshot of the hierarchy of the cube in case it matters: http://i.imgur.com/hg13kT0.png?1?8837 All sub-cubes contain the same components.

avatar image Dracorat · Oct 30, 2013 at 08:08 PM 1
Share

Continuous dynamic attempts to alter a RigidBody's position if it's intersecting with another. Since the usual alter direction would be invalid, it is struggling with it. It's also a very expensive algorithm. You'd use it only if you believe an object is moving so fast that it might pass completely through something in between frames.

Show more comments

2 Replies

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

Answer by Paparakas · Oct 30, 2013 at 09:16 PM

Changing the collision detection from continuous dynamic to discrete worked. Alternatively not rotating the object also made the problem go away. Explanation by @Dracorat as to the why of the problem:

"Continuous dynamic attempts to alter a RigidBody's position if it's intersecting with another. Since the usual alter direction would be invalid, it is struggling with it. It's also a very expensive algorithm. You'd use it only if you believe an object is moving so fast that it might pass completely through something in between frames."

Comment
Add comment · 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
0

Answer by memblock · Oct 30, 2013 at 06:45 PM

Hmmm,,, not sure why it lags. I played around with a simple 'follow-player' script. It never turned out into anything useable but I simply med use of the Vector3.Lerp command. Check into that,,, maybe it can help you out. Best of luck!

Comment
Add comment · 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

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

19 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

Related Questions

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

Very Bad Lag from ~20 Large Particles 0 Answers

Android lag 1 Answer

WebGl Using too much memory 1 Answer

OnTriggerEnter causing lag spike? 0 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