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 /
  • Help Room /
avatar image
0
Question by SuperMalvado592yt · Aug 11, 2020 at 10:15 AM · gameobjectfpsrigidbody2dmovement script

GameObjects move slower at 9 FPS or less.

Hi. I'm getting started in Unity and currently I'm working in a TowerDefence 2D game. I am having an issue with the GameObjects and their movements. Some gameObjects use rigidbodies to move and other use "transform.Translate", but both get the same problem. I know that the frames per second affect the Update() method, so if there are less FPS or more, the velocity of the GameObjects that use that method to move can be different. I have looked in other Unity answer pages for this and I changed the method to FixedUpdate(). Now here is the problem:

,

Now the velocity of the GameObject is constant, no matter what FPS there are, but if there are less than 10. I've tried with 400 FPS, 300FPS, 120FPS, 60FPS, 30FPS, 10FPS. In all of these the speed of the GameObjects is the same and finishes moving at the same time, but when I change the FPS limit to lower than 10, the speed starts to change. At 5 FPS it can be different by some seconds to finish the movement stablished by SCRIPT. Now the issue that was solved was showing in this range, 1 to 9 fps. The more Fps in these, the faster, but the GameObjects always move slower than at 10 or more FPS (that it is constant).

,

I leave here one SCPIPT that I use. It isn't the only one, but all of the others are the same, but with other functions of hurting and dealing damage to other objects.

,

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Proyectil : MonoBehaviour {

 GameObject[] enemyes;
 List<GameObject> collisions = new List<GameObject>();

 public Sprite sprite1;
 public Sprite sprite2;

 float tiempo = 0f;


 [HideInInspector]
 public bool aliado;
 [HideInInspector]
 public float velocity;
 [HideInInspector]
 public bool area;
 [HideInInspector]
 public int dañar;
 [HideInInspector]
 public float yPosition;

 private Rigidbody2D rb;
 // Start is called before the first frame update
 void Start()
 {
     tiempo = 0f;
     rb = GetComponent<Rigidbody2D>();

 }

 // Update is called once per frame
 void FixedUpdate()
 {
     if (aliado == true)
     {
         rb.velocity = Vector2.right * velocity;
     }
     else
     {
         rb.velocity = Vector2.left * velocity;
     }
     gameObject.transform.position = new Vector3(gameObject.transform.position.x, yPosition, gameObject.transform.position.z);
 }

 void Update()
 {
     tiempo += Time.deltaTime;

     if (tiempo > 0.5f)
     {
         gameObject.GetComponent<SpriteRenderer>().sprite = sprite2;
     }
     else
     {
         gameObject.GetComponent<SpriteRenderer>().sprite = sprite1;
     }

     if (tiempo > 1f)
     {
         tiempo = 0f;
     }
 }


 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (aliado == true)
     {
         if (collision.transform.tag == "Enemigo")
         {
             collisions.Add(collision.gameObject);
             enemyes = collisions.ToArray();

             if (area == false)
             {
                 enemyes[0].GetComponent<Enemy>().hurted2(dañar);
             }
             else
             {
                 foreach(GameObject value in enemyes)
                 {
                     value.GetComponent<Enemy>().hurted2(dañar);
                 }
             }
             //ATAQUE
             Destroy(gameObject);
         }
     }
     else
     {
         if (collision.transform.tag == "Alimento")
         {
             if (collision.GetComponent<Alimento>().Inicio == true)
             {
                 collisions.Add(collision.gameObject);
                 enemyes = collisions.ToArray();

                 enemyes[0].GetComponent<Alimento>().hurted(dañar);

                 Destroy(gameObject);
             }
         }

         if (collision.transform.tag == "PLAYER")
         {
             collisions.Add(collision.gameObject);
             enemyes = collisions.ToArray();

             enemyes[0].GetComponent<jugador>().hurted(dañar);

             Destroy(gameObject);
         }
     }

     if (collision.transform.tag == "ParedParProy")
     {
         Destroy(gameObject);
     }
 }

Summary:

I put in the movement of all GAMEOBJECTS in FixedUpdate() method and their speed is always constant in all FPS but at 9 FPS or less. If FPS are less than 10, their speed of movement change and they become slower. If someone know something about this, please tell me. Thanks for the help, hope I explained well and that the script is enought.

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

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

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

Problems with Movement on rigged 2d animation., 0 Answers

I want to rotate the 2D missile with touch controls 1 Answer

Having multiple UNET errors that I believe are caused by unity itself. Am I doing something wrong? 1 Answer

Limiting backwards speed ,Limiting backwards speed 0 Answers

[UNET] Having problems with clients not being able to shoot after they reload 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