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 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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

FPS Movement Incredibly Laggy 0 Answers

First Person Controller movement Lag? 1 Answer

Replacing iTween.MoveUpdate with iTween.MoveTo 1 Answer

Character Controller has Input Lag. How do I Fix it? 0 Answers

Mobile Movement Choppy in 2d endless runner 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