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 superch · Aug 30, 2016 at 05:05 PM · c#performancerts

Issues with movement in an RTS Game.

After two years of programming in Unity with a couple of friends, I had to move away from them. Becaus of this and the fact that I had to leave our project, I decided to start my own. I decided it would be an RTS because of my love for the genre. I have, however, run into an issue. When I tested the script below on one of my basic units it worked fine. However, my problem is the fact that when I spawn more units the Game's framerate suddenly drops. I don't even have to spawn many units for this to happen. Often five is the amount that is needed before the game becomes completely unplayable. I hope some of you can help me with this, and would appreciate it if you could. My friends and I also had the same issue back when I was coding with them.

Here's the script. I have tried deactivating the Navmesh.

using UnityEngine; using System.Collections;

public class villager_behaviour_1 : MonoBehaviour {

 //Villager_components
 private GameObject villager;
 //Villager_movement;
 [SerializeField]
 private bool selected;
 [SerializeField]
 private float speed_move;
 private float standard_speed;
 [SerializeField]
 private float speed_rotate;
 [SerializeField]
 private Vector3 newposition;
 private float villager_y;
 private NavMeshAgent agent;
 private bool leftclick_exit = true;

 void Start ()
 {
     //Villager_components
     villager = this.gameObject;
     //Villager_movement
     newposition = villager.transform.position;
     standard_speed = speed_move;
     agent = villager.GetComponent<NavMeshAgent>();
     villager_y = villager.transform.position.y;
 }

 void FixedUpdate ()
 {
     agent.speed = speed_move;
     agent.angularSpeed = speed_rotate;

     if ((Input.GetMouseButtonDown(0)))
         if (leftclick_exit == true)
             selected = false;

     RaycastHit hit_screen_position;
     Ray ray_screen_position = Camera.main.ScreenPointToRay(Input.mousePosition);

     if (Input.GetMouseButtonUp(1))
     {
         if (selected == true)
         {
             if (Physics.Raycast(ray_screen_position, out hit_screen_position, 500))
             {
                 newposition = hit_screen_position.point;
             }
         }
     }
     agent.SetDestination(newposition);

     newposition.y = villager_y;      
 }

 void OnMouseEnter ()
 {
     leftclick_exit = false;
 }

 void OnMouseDown ()
 {
     selected = !selected;
     
 }

 void OnMouseExit ()
 {
     leftclick_exit = true;
 }

}

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 juicyz · Aug 30, 2016 at 05:25 PM 0
Share

Any reason why you are doing this in FixedUpdate ins$$anonymous$$d of Update? FixedUpdate is typically for physics. I would also suggest putting the Raycast functions inside the $$anonymous$$ouseUp Events as you are doing unnecessary raycasts and not using them. All your villagers are doing a ton of raycasts

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

IL2CPP Unused local just for stack balance error 0 Answers

RTS dynamic formation width and length 0 Answers

What`s more expensive GUI Texures or Quads for displaying units health?(RTS) 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