This code (magnet) gives 2 -3 fps when turned on, without it - 70 fps. Provided that the magnet attracts 2-3 rigidbody. Without objects near it does not hang at all, with one object - 60 fps, with two or three drops to 3 fps;
public class MAGNETO : MonoBehaviour { public float radiusdal; Transform mytr; public float forcedal; // Use this for initialization void Start() { mytr = transform; } // Update is called once per frame void FixedUpdate() { Collider[] coldal = Physics.OverlapSphere(mytr.position, radiusdal); foreach (var col1 in coldal) { //ΠΠΎΡ Π΅ΡΠ»ΠΈ ΡΡΠΎΡ ΠΊΡΡΠΎΠΊ ΠΊΠΎΠ΄Π° ΡΠ±ΠΈΡΠ°Π΅ΠΌ - ΠΌΠ°Π³Π½ΠΈΡ Π½ΠΈΡΠ΅Π³ΠΎ Π½Π΅ ΠΏΡΠΈΡΡΠ³ΠΈΠ²Π°Π΅Ρ, Π½ΠΎ ΠΈ Π²ΠΎΠΎΠ±ΡΠ΅ Π½Π΅ ΡΠΎΡΠΌΠΎΠ·ΠΈΡ. if (col1.attachedRigidbody != null) { var ux = Vector3.Distance(mytr.position, col1.transform.position); var aux = 0.5f / (ux); col1.attachedRigidbody.AddForce((mytr.position - col1.transform.position)* aux* forcedal, ForceMode.VelocityChange); }// Π·Π°ΠΊΠΎΠ½ΡΠΈΠ»ΠΈ ΡΠΎΡΠΌΠΎΠ·ΡΡΠΈΠΉ ΠΊΡΡΠΎΠΊ ΠΊΠΎΠ΄Π°. } } }
collider.attachedRigidbody
was taken as a replacement for GetComponent<Rigidbody>
, but the result is exactly the same: 2-3 fps.
OverlapSphere
recording, your magnet will also get into theOverlapSphere
array, since you have assigned his position to the center. Maybe (and vdruuuuuuuug) the point is this and you need to write at leastif (col1.attachedRigidbody != null && col1.gameObject.name != "myMagnetObjectName") {
....... although without this you should get an error , but apparently you ignore the error)) - Alexey ShimanskyΠ½Π΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· ΡΡΠΈΡ ΡΠ΅Π» ΠΈΠΌΠ΅ΡΡ ΡΠΎΠ±ΡΡΠ²Π΅Π½Π½ΡΠ΅ ΡΠΊΡΠΈΠΏΡΡ Ρ addforce - ΠΎΠ½ΠΈ Π΄ΠΎΠ»ΠΆΠ½Ρ ΠΏΡΠ΅ΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΡ ΡΠ΅Π»Ρ
and who should they pursue? show their code. maybe the truth is with them what is happening ..... And so - the problem is not reproducible - Alexey Shimanskyvoid Start () { rb = GetComponent<Rigidbody>(); myTransform = transform; } // Update is called once per frame void FixedUpdate () { myTransform.LookAt(player.transform.position); rb.AddForce(myTransform.forward * enemy1speed, ForceMode.Force); }
void Start () { rb = GetComponent<Rigidbody>(); myTransform = transform; } // Update is called once per frame void FixedUpdate () { myTransform.LookAt(player.transform.position); rb.AddForce(myTransform.forward * enemy1speed, ForceMode.Force); }
void Start () { rb = GetComponent<Rigidbody>(); myTransform = transform; } // Update is called once per frame void FixedUpdate () { myTransform.LookAt(player.transform.position); rb.AddForce(myTransform.forward * enemy1speed, ForceMode.Force); }
- Dmitrii