The program pulls the cursor behind the rigidbody, the cursor shoots with a raikast. For some reason, during the movement, everything starts to slow down wildly. Without movement 72 fps, with it 6 fps. What is it and how to deal with it. GetComponent in Update like not.
The contents of the script that slows down. Disabled the rest - anyway, maximum 15 fps in motion.
public class RayCaster : MonoBehaviour { private Ray ray; private RaycastHit hit; public float speedphys; public GameObject player; Rigidbody rb; // Use this for initialization void Start () { rb = player.GetComponent<Rigidbody>(); } // Update is called once per frame void FixedUpdate() // ΡΠ°ΠΊ ΠΊΠ°ΠΊ ΠΌΡ ΡΠ°Π±ΠΎΡΠ°Π΅ΠΌ Ρ ΡΠΈΠ·ΠΈΠΊΠΎΠΉ Π² Unity, FixedUpdate ΠΏΡΠ΅Π΄ΠΏΠΎΡΡΠΈΡΠ΅Π»ΡΠ½Π΅Π΅ ΠΎΠ±ΡΡΠ½ΠΎΠ³ΠΎ Update { //ΠΠΎΠ΄ ΡΠ°Π·Π½ΡΠ΅ ΠΏΠ»Π°ΡΡΠΎΡΠΌΡ Π½Π°ΠΌ ΡΡΠ΅Π±ΡΠ΅ΡΡΡ ΡΠ°Π·Π½ΡΠΉ ΠΊΠΎΠ΄. #if UNITY_EDITOR ForUnityEditorAndPC(); #endif #if UNITY_ANDROID ForAndro(); #endif #if UNITY_STANDALONE ForUnityEditorAndPC(); #endif } void ForUnityEditorAndPC() { if (Input.GetMouseButton(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); // ΠΡΠ»ΠΈ Π΄Π΅Π»ΠΎ ΠΈΠΌΠ΅Π΅ΠΌ Ρ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠΎΠ² - ΠΈΠ· ΠΌΡΡΠΊΠΈ Π»ΡΡ ΠΏΡΡΠΊΠ°Π΅ΠΌ raycast(); } } void ForAndro() { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); // ΠΡΠ»ΠΈ Π°Π½Π΄ΡΠΎΠΈΠ΄ - ΡΠΎ ΠΈΠ· ΡΠ°ΡΠ°, ΠΊΠΎΠ³Π΄Π° ΠΎΠ½ Π΄Π²ΠΈΠΆΠ΅ΡΡΡ. raycast(); } } void raycast()//ΠΡΠΎΡ ΠΊΠΎΠ΄ Π΄Π»Ρ ΠΎΠ±ΠΎΠΈΡ
ΡΡΡΡΠΎΠΉΡΡΠ² ΠΎΠ±ΡΠΈΠΉ, Π½Π΅Ρ ΡΠΌΡΡΠ»Π° Π΅Π³ΠΎ Π΄ΡΠ±Π»ΠΈΡΠΎΠ²Π°ΡΡ. Π’ΡΡ ΠΌΡ ΡΠΌΠΎΡΡΠΈΠΌ, ΠΊΡΠ΄Π° ΡΠΏΠ°Π» Π»ΡΡ { if (Physics.Raycast(ray, out hit) && !hit.collider.CompareTag("Player")) { var dir = (hit.point - player.transform.position); player.transform.DOLookAt(hit.point, 0.1f); Debug.Log(hit.point); rb.velocity = new Vector3(dir.x, 0, dir.z) * speedphys; //ΠΠ²ΠΈΠ³Π°Π΅ΠΌ ΠΊΠΎΠ»Π»Π°ΠΉΠ΄Π΅Ρ ΠΊ ΠΌΠ΅ΡΡΡ ΠΊΡΠ΄Π° Π»ΡΡ ΡΠΏΠ°Π». Rigidbody ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌ, ΡΠ°ΠΊ ΠΊΠ°ΠΊ ΡΠΈΠ·ΠΈΠΊΠ°, Π΄Π° ΠΈ ΡΠΈΠ»Ρ ΡΠ»ΠΈΡΠΊΠΎΠΌ ΠΌΠ½ΠΎΠ³ΠΎ Π±ΡΡΡ //Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ - Π° ΡΠΎ ΡΠ°ΡΠΊΠΈΠ΄Π°Π΅Ρ ΡΠΈΡΠΊΠΈ ΠΎΡΡΠ°Π»ΡΠ½ΡΠ΅. Π‘ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠΎΠΌ speedphys Π»Π΅Π³ΠΊΠΎ ΡΠ΅Π³ΡΠ»ΠΈΡΠΎΠ²Π°ΡΡ ΡΠΊΠΎΡΠΎΡΡΡ ΠΊΠΎΠ»Π»Π°ΠΉΠ΄Π΅ΡΠ° ΠΏΡΡΠΌΠΎ //ΠΈΠ· ΡΠ΅Π΄Π°ΠΊΡΠΎΡΠ°, Π½Π΅ Π·Π°Π³Π»ΡΠ΄ΡΠ²Π°Ρ Π»ΠΈΡΠ½ΠΈΠΉ ΡΠ°Π· Π² ΠΊΠΎΠ΄. Debug.Log(hit.point + " hitpoint"); //Debug.Log(transform.position + " transform.position"); } } }