Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
3
Question by Bibrosko · Aug 18, 2019 at 03:58 PM · rigidbodyplayertimespeed

Player acts differently if not selected in the inspector

Hi all, I hope someone could help me. I'm making a roll-a-ball game involving forces, speed and timescale. I notice a weird behaviour while playing: IF the player game object is selected in the inspector, everything works correctly as I intended in my scripts. IF NOT the player acts very differently, the applied force is weaker (so that I cannot reach the max speed), the "spin" value I created, which should decrease by 0.1 on each click, depleates with a different speed, the regeneration of the same value is faster then normal etc... Maybe it's something related to the new prefabs system of some mistake I made manipulating the timescale (and the related fixed delta time). Please help! Here's the script:

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 using System.Collections;
 
 
 class PHOTON : MonoBehaviour
 {
     public Rigidbody PhotonRB;
     public float pushForce;
     public float spinMax = 1;
     public float spin = 1;
     public float spinRegRate = 0.1f;
     private Plane plane = new Plane(Vector3.up, Vector3.zero);
     public AudioSource moveSound;
     public Light photonLight;
     public bool isLightSpeed = false;
 
     private void Start()
     {
         moveSound = GetComponent<AudioSource>();
         StartCoroutine(regenerateSpin());
         spin = spinMax;
         spinRegRate = PlayerPrefs.GetInt("PlayerNewLevel");
     }
 
     public void LevelUp()
     {
         spinRegRate = PlayerPrefs.GetInt("PlayerNewLevel");
     }
 
     private void Update()
     {
         if (transform.position.y >= 5)
         {
             transform.position = new Vector3(transform.position.x, 0, transform.position.z);
         }
 
         if (Input.GetMouseButtonDown(0) && isLightSpeed == false && spin >= 0.1f)
         {
             decreaseSpin(0.1f);
 
         }
 
 
         if (Input.GetMouseButtonDown(0) && isLightSpeed == true)
         {
             RaycastHit hit;
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out hit, 100.0f))
                 if (hit.collider != null)
                 {
                     transform.position = new Vector3(hit.point.x, 0.5f, hit.point.z);
                     Debug.Log("hit" + hit.collider.name);
                 }
         }
         else
         {
             return;
         }
     }
     void decreaseSpin(float amount)
     {
         spin -= amount;
 
         if (spin <= 0)
         {
             spin = 0;
         }
     }
 
     IEnumerator regenerateSpin()
     {
         while (true)
         {
             if (spin < 1)
             {
                 spin += spinRegRate * 0.001f;
                 yield return new WaitForSeconds(0.01f);
             }
             else
             {
                 yield return null;
             }
         }
     }
 
     IEnumerator lightSpeed()
     {
         isLightSpeed = true;
         Time.timeScale = 0.05f;
         PhotonRB.isKinematic = true;
 
 
         yield return new WaitForSeconds(0.5f);
      
 
         isLightSpeed = false;
         Time.timeScale = 1f;
         PhotonRB.isKinematic = false;
         //LightSpeedSlider.gameObject.SetActive(false);
     }
 
 
     private void FixedUpdate()
     {
         photonLight.intensity = Mathf.Lerp(1f, 30f, PhotonRB.velocity.magnitude/100);
        // photonLight.range = (PhotonRB.velocity.magnitude);
         PhotonRB.mass = Mathf.Lerp(1f, 0.01f, PhotonRB.velocity.magnitude / 100);
         PhotonRB.drag = Mathf.Lerp(0f, 1f, PhotonRB.velocity.magnitude / 1000);
 
         if (PhotonRB.velocity.magnitude >= 100f)
         {
             StartCoroutine(lightSpeed());
         }
 
         if (Input.GetMouseButtonDown(0) && isLightSpeed == false)
         {
             moveSound.Play();
             var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             float enter;
 
             if (plane.Raycast(ray, out enter))
             {
                 var hitPoint = ray.GetPoint(enter);
                 var mouseDir = hitPoint - gameObject.transform.position;
                 mouseDir = mouseDir.normalized;
                 PhotonRB.AddForce(mouseDir * pushForce);
             }
         }
     }
 }
Comment
Add comment · Show 2
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 Oc7i · Apr 25, 2020 at 02:05 AM 0
Share

I am having the same problem with Unity 2019.3.11

A player object with Rigidbody2D and Collider2D checks if it is grounded via getting its collider's contact points. Jumping depends on being grounded first. When standing on a vertically moving platform, the grounded bool of the player object unpredictably shifts between true and false when the platform is moving (this happens in a build of the game too). If the object is selected in the inspector, this no longer happens and the grounded bool, along with its jump, work as expected.

Any chance you might have figured out the cause of this strange behavior?

avatar image Mohammad_Alsaad · Apr 03, 2021 at 06:34 PM 0
Share

Same problem here, but with Scriptable Object. A Bool doesn't change from true to false if the scriptable object isn't selected to be viewed in inspector.

6 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Hecklatch · Feb 18, 2020 at 11:45 AM

@Bibrosko Hey, did you ever figure out what was causing the issue ? I'm dealing with exactly the same problem and I have no idea what might be the cause.

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
1

Answer by Kahun4 · Apr 29, 2020 at 11:18 AM

I had the same sort of problem and solved it by moving the methods that handled movement of the rigidbody of the player from Update to FixedUpdate.

Comment
Add comment · 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
0

Answer by unity_wjfOb90B6Ao9WA · Dec 19, 2021 at 10:10 PM

I'm facing the same issues. In my case, there's a player ( downloaded from a prefab ) that is standing on a platform ( platform is its parent ), and the platform is based on AR, so it appears on a QR code printed on a paper, and moves if the paper moves. The player is always offsetted, not following at all the platform and it feels like he's sliding. But when focusing with the inspector, everything becomes fine. Any updates on this ?

Comment
Add comment · 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
0

Answer by WorldFlickers · Dec 28, 2021 at 07:32 PM

I got similar problem. I had a swinging anchor attached to a cube with rigidbody. And when I selected the cube in scene hierarchy, swinging became faster. I limited app fps with 30, and difference disappeared. Seems like app in editor works slower, with less fps, when a rigidbody is selected in scene hierarchy. And it means that your behaviour depends on fps.

Comment
Add comment · 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
0

Answer by rigidbodyinteractive · Dec 30, 2021 at 04:22 AM

I filed a bug report to Unity about this issue. They said it was a confirmed bug and it will be fixed in future releases.

https://issuetracker.unity3d.com/issues/start-and-update-methods-are-not-called-after-duplicating-gameobject-with-particle-system-component

Although I didn't notice any improvement in 2020.3.16.f version (i did not upgrade to the latest one yet).

What version are you guys using?

Comment
Add comment · 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
  • 1
  • 2
  • ›

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

173 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

Related Questions

When I use rigidbody.Moveposition, the object doesn't move accurately. 1 Answer

Increase time for rigidbody game objects? 1 Answer

Time.deltaTime problems? 1 Answer

WheelColliders Bug Fix 0 Answers

Disable/Change gravity effects on inclined platforms 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