Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Player stopping minutely after certain amount of time.

Discussion in 'Physics' started by eraban, Dec 4, 2020.

  1. eraban

    eraban

    Joined:
    Jul 19, 2020
    Posts:
    1
    I have been trying hard to fix this, but I cant figure out any solution.
    This is in in the editor:

    This is in the build in mobile phone:

    As you can see the sphere is stopping minutely after a certain amount of time in the build. These are the Scripts:

    This is the movement Script:
    Code (CSharp):
    1.  using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class Movement : MonoBehaviour
    5. {
    6.      public GameObject gun;
    7.      public int speed = 10;
    8.      public Rigidbody rb;
    9.      float h;
    10.      float v;
    11.    
    12.      public Joystick joystick;
    13.      // Update is called once per frame
    14.      void FixedUpdate()
    15.      {
    16.          h = joystick.Horizontal;
    17.          v = joystick.Vertical;
    18.          GetComponent<Rigidbody>().AddForce(Vector3.forward * speed * v);
    19.          GetComponent<Rigidbody>().AddForce(Vector3.right * speed * h);
    20.          rb.velocity = rb.velocity * (1 - Time.deltaTime * rb.drag);
    21.      }
    22.      private void Update()
    23.      {
    24.          gun.transform.position = transform.position;
    25.      }
    26. }
    This is the gun script:
    Code (CSharp):
    1.  using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class Gun : MonoBehaviour
    5. {
    6.      public Joystick joystick;
    7.      float yaw;
    8.      public float LerpSpeed;
    9.      private float finalYaw;
    10.      public float turnSpeed;
    11.      // Start is called before the first frame update
    12.      void Start()
    13.      {
    14.        
    15.      }
    16.      // Update is called once per frame
    17.      void FixedUpdate()
    18.      {
    19.          finalYaw = Mathf.Lerp(finalYaw, yaw, Time.deltaTime * LerpSpeed);
    20.          yaw += joystick.Horizontal * turnSpeed;
    21.          transform.eulerAngles = new Vector3(transform.rotation.x, -finalYaw, transform.rotation.y);
    22.      }
    23. }
    This is the Camera Script(I copied it from the internet):
    Code (CSharp):
    1.  using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class CameraMovement : MonoBehaviour
    5. {
    6.      public GameObject player;        //Public variable to store a reference to the player game object
    7.      private Vector3 offset;            //Private variable to store the offset distance between the player and camera
    8.      // Use this for initialization
    9.      void Start()
    10.      {
    11.          //Calculate and store the offset value by getting the distance between the player's position and camera's position.
    12.          offset = transform.position - player.transform.position;
    13.      }
    14.      // LateUpdate is called after Update each frame
    15.      void LateUpdate()
    16.      {
    17.          // Set the position of the camera's transform to be the same as the player's, but offset by the calculated offset distance.
    18.          transform.position = player.transform.position + offset;
    19.      }
    20. }
    This is My Hierarchy:

    As you can guess the parent "Player" is not moving. The sphere is moving and the gun is simply following the position of the sphere.

    I don't understand why the sphere is stopping minutely after a certain amount of time. The sphere is not stopping because of sphere is colliding with the gun. The gun is at a considerable distance form the sphere. Can Some one please help me.