Point of Input Emits Force on a Foreign Object

Hey all,

I’m looking to write something in C# that will work as follows. The user touches a point on the screen (temporarily mapped to a mouse button press) and a petal will float in the opposite direction of the input so long as it is within the effective radius.

Imagine that the user touches a point on the screen and it generates a gust of wind towards the petal - pushing it along. Of course the force of the wind will weaken with distance.

I haven’t started writing anything yet, I’m still trying to figure out how to do it all. I imagine that I’ll be using some sort of Raycast that extends in a 360 degree radius around the Input point. If it collides with the petal (a rigidbody) there will be some sort of Rigidbody.Addforce effect that pushes the petal.

Does this sound like I’m on the right track or do you think I should be investigating other keywords?

Just to be clear, I’m not asking for code - just whether you think I’m on the right track for what I want to accomplish.

alt text

A raycast is probably not the way to go- it only goes in one direction! If you wanted to go in all directions, you’d have to do like a gazillion of them.

Try using Physics.SphereCastAll to return an array of objects within a certain distance of the point- you can then apply your force to the petal as long as it remains in range!

EDIT:

Whoops, I was thinking of Physics.OverlapSphere- that’s probably more like what you’re after.