Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

C# script not working

$
0
0
here is a script i put on a trigger collider on my tornado which does the physics for my tornado. there are no errors in the script. but it isnt making my rigidbodies do anything. whats the problem? Vector3 origin; //Should be set to Tornado's base [SerializeField] float tornadoHeight = 40f; [SerializeField] float strength = 20f; [SerializeField] float accelerationFactor = 1.1f; [SerializeField] float yPush = .2f; List entities = new List(); float sqrStrength = 400f; void OnValidate() { sqrStrength = strength * strength; } void FixedUpdate() { foreach (Rigidbody entity in entities) { Vector3 relPos = entity.transform.position - origin; if (relPos.y > tornadoHeight || relPos.x * relPos.x + relPos.z * relPos.z > relPos.y * relPos.y) continue; entity.velocity = entity.velocity * accelerationFactor; float sqrVelocity = entity.velocity.sqrMagnitude; if (sqrVelocity > sqrStrength) sqrVelocity = sqrStrength; float sqrRadius = relPos.sqrMagnitude; Vector3 radialAcceleration = - relPos * sqrVelocity / sqrRadius; radialAcceleration.y = radialAcceleration.y + yPush; entity.AddForce(radialAcceleration); } entities.Clear(); } void OnTriggerStay(Collider other) { Rigidbody rigidbody = other.gameObject.GetComponent(); if (rigidbody != null && !entities.Contains(rigidbody)) entities.Add(rigidbody); } }

Viewing all articles
Browse latest Browse all 1264

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>