Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 qwertyp · Jul 01, 2011 at 09:32 PM · platformerlagmoving-platform

Massive lag moving platforms

The following code powers my moving platforms. However, if there are more than 3 or so, I start to experience massive lag. As in 3 FPS lag. This seems really excessive for what I'm doing. Ideas on streamlining this? Am I doing something that really chews memory?

EDIT: I have tracked the problem down to the lines of code that scale the piston. Is scaling every frame really slow or something?

 var Top : GameObject;
 var Piston : Transform;
 var Sound : AudioSource;
 var HeightToLift : float;
 var Speed : float;
 var usingButton : boolean;
 var linkedButton : ButtonControl;
 
 function FixedUpdate () {
     if (Top.transform.localPosition.y > HeightToLift || Top.transform.localPosition.y < 0) { // Flip direction @ ends
         Speed *= -1;
     }
             
     if (usingButton == true) {
         if (linkedButton.buttonPressed) {
             Top.rigidbody.MovePosition(Top.rigidbody.position+(transform.up * Time.deltaTime * Speed * 3));
             Piston.localScale.z += Time.deltaTime * Speed; //THIS LINE
             if (Sound.isPlaying == false) {
                 Sound.Play();
             }
         } else if (Sound.isPlaying == true) {
             Sound.Stop();
         }
     } else {
         Top.rigidbody.MovePosition(Top.rigidbody.position+(transform.up * Time.deltaTime * Speed * 3));
         Piston.localScale.z += Time.deltaTime * Speed; // AND THIS LINE
         if (Sound.isPlaying == false) {
             Sound.Play();
         }
     }
 }
Comment
Add comment · Show 4
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 Graham-Dunnett ♦♦ · Jul 02, 2011 at 08:12 PM 0
Share

Nothing shouts out in the code as problematic. What makes you think this code is responsible for the lag?

avatar image SilverTabby · Jul 02, 2011 at 09:53 PM 0
Share

The only thing I can see is that you are using a rigidbody when It seems that a collider sans rigidbody would work fine for the purposes of the lift.

Also make sure that the piston and the Top can't collide with each other. I once doubled my framerate by changing a few collision flags along those lines.

avatar image qwertyp · Jul 03, 2011 at 12:59 AM 0
Share

@Graham: See my edit above

@SilverTabby: Tried that. It helped some, but I'm still running around 10 FPS. I use a rigidbody as I found the physics were more realistic with the rigidbody. (Platform pushing stuff through walls, etc.)

avatar image aldonaletto · Jul 03, 2011 at 02:08 AM 0
Share

Are the rigidbodies kinematic? $$anonymous$$inematic rigidbodies are more adequated for moving parts not subject to physics (see http://unity3d.com/support/documentation/Components/comp-DynamicsGroup.html). You could also try to remove the rigidbodies just to check how much it influences the FPS.

1 Reply

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

Answer by Dreamora · Jul 04, 2011 at 03:13 AM

Do you by error use a mesh collider? If so ensure its selected to be convex, you must never move mesh colliders that are not convex as the whole collision tree gets constantly updated and thats an extremely cpu intense work, if you get close to detailed meshes or the terrain it can even become a neck breaking bottleneck.

If a single collider can't represent a more complex shape that would not be able to work with convex mesh collider, use subobjects that only have a collider on them (normally primitive) and try to represent it that way. or rework the model to visually represent what you physically need for it to have it working reasonably.

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 qwertyp · Jul 04, 2011 at 03:41 AM 0
Share

I'd actually switched to a box collider shortly before you posted this, but thanks for the explanation on the problem. I'll file this for future reference. 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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Stay on Moving Platform without Character Controller 1 Answer

Rigidbody on a moving platform 6 Answers

Horizontal platform passes through CharacterController 4 Answers

Keeping the player on a moving platform? 0 Answers

Problem with moving platform and gun placment 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