|
How can I affect all objects currently in a collider trigger's space? I want to be able to constantly affect all the objects' velocities in a spherical radius around the player (excluding some), whenever the player holds left click, but if he lets go then everything returns to normal. The unity scripting reference page isn't so helpful.. but i think Collider.OnTriggerStay is the way? There is no explanation on how to use it, especially in my case. Thanks a ton!!!!
(comments are locked)
|
|
You might be better off looking at Physics.OverlapSphere. This function returns an array with all colliders touching or inside the sphere, and sounds pretty much ideally suited to your question. You'd then want to loop through the list of returned colliders in order to apply the force to them, and since you're applying physics forces, all this code should go in your FixedUpdate() function. Something like this:
(comments are locked)
|
|
Yes, OnTriggerStay is one way to do it. You could also do OnTriggerEnter, set some kind of scalar on all the objects (like speed or whatever), and then set it back to the original value with an OnTriggerExit.
(comments are locked)
|
|
I know its probably sloppy, and lazier than doing Physics.Overlapsphere, but I sometimes like to attach a sphere collider to whatever I am putting trigger code on and hiding the mesh renderer in the inspector. Why would you do this? To have a visual of the sphere in the editor?
Mar 23 '10 at 02:38 PM
Ben Throop
(comments are locked)
|
