• 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 Christopher Winstanley · Sep 13, 2010 at 10:48 AM · movementlag

Lag in Game making character jump

Hi Everyone,

My character is moving fine when there is limited things on the screen (a few spheres rotating), but when I add more, than 5 spheres or add a particle effect to one of them I get severe lag of the character when it moves (it jumps around the target position).

I was wondering if anybody could see anything in my code that could be changed to avoid the jumping or let me know a way to reduce the lag without taking objects out.

function CharacterControl() { var count : int = iPhoneInput.touchCount; if(state == ControlState.TrackingMove) { var touch : iPhoneTouch = iPhoneInput.GetTouch(0);

     if(touch.position.y > firingBorder && touch.position.y < 450)
     {

         var ray = cam.ScreenPointToRay( Vector3( touch.position.x, touch.position.y ) );
         var hit : RaycastHit;
         if( Physics.Raycast(ray, hit) )
         {
             var touchDist : float = (transform.position - hit.point).magnitude;
             if( touchDist > minimumDistanceToMove )
             {
                     targetLocation = hit.point;
             }
             moving = true;
         }
     }
     else
     {
         ResetControlState();    
     }

 }

 movement = Vector3.zero;
 rotate = Vector3.zero;

 if(state == ControlState.MovingCharacter)
 {
 if( moving )
 {
     // Move towards the target location
     movement = targetLocation - thisTransform.position;
     movement.y=0;
     movement.z=0;

     var dist : float = movement.magnitude;
     if(movement.x < 0)
     {
         rotate = Vector3(0,0,25);
     }

     if(movement.x > 0)
     {
         rotate = Vector3(0,0,-25);
     }
     if( dist < 1 )
     {
         moving = false;
         ResetControlState();
         rotate = -rotate;
     }
     else
     {
         movement = movement.normalized * speed;
     }
 }

 movement += velocity;       
 movement += Physics.gravity;
 movement *= Time.deltaTime;

 // Actually move the character
 character.Move( movement );
 character.transform.Rotate(rotate);
 velocity = Vector3.zero;
 }

}

Thanks

Chris

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
1
Best Answer

Answer by spinaljack · Sep 13, 2010 at 11:34 AM

Couple things:

  1. If the particle effects are the only things using physics you can lower fixed time right down, something like 0.6 or higher, this wont work if your character moves with physics though1.
  2. Lower draw calls, if you have several objects in the scene you can make them share a single texture to increase the amount of batching going on. Just stick all your textures onto a single huge texture
  3. Similar to item 2, reduce memory usage by reducing texture size and quality, generally for 3D objects 256 or even 128 will do
  4. Reduce mesh size, you can model all the objects in a room into a single mesh and then you can remove all the reverse side polys. Also consider using culling if your character regularly moves between rooms, by setting objects to static and creating a few bounding zones you can cull all the objects in a room you're not in speed things up.
  5. Use fewer particles, you've said you didn't want to remove them but you can usually pull off the same effect with fewer particles by animating them or using a single animated texture instead of complex particles
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 Christopher Winstanley · Sep 13, 2010 at 11:48 AM 0
Share

thanks so much this sound like it could definitely work in my case 3 or 4 sound most promising ill give it a try 2moro n let you know

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

(NEW USER) 2D character movement is laggy 0 Answers

Input lag on Andorid but not in Unity 1 Answer

Touch Delay / Lag in Movement only on iOS Device 0 Answers

How do i Smooth ingame movement with flickering sensor input? 0 Answers

Simple movement causing lag (on standalone) 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