|
Hi, The Problem is still Buggy: When the player is outside of the radius, when the Player stops, turns around (or move backwards), and then proceeds toward the radius, my varaible still decrements! Bad. If I am outside of the radius, and proceed closer to the radius, I need to be incrementing... I set up the below Vector3.Distance with if else blocks because I think it works more to my expectations than overlap sphere!
What I mean by buggy, is that when the player moves away from the object, rotates 180 degrees, then moves back toward the object, the varaible decrements.....when it should increment. I have tested this thoroughly and what I am telling is what unfortunately happens. It would also be nice, if I could somehow use the radius like in OverlapSphere, that way I don't have to get incredibly close to the object for my varaible to increment.
(comments are locked)
|
|
The problem with your logic and your desired results doesn't seem to be the overlap sphere bit, but you need the logic for "am I moving towards the sphere". For that there's an easy solution. Assuming you have the forward vector of the player's movement, you can do something like this.
Although not Unity documentation, a good resource on the dot product can be found here: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector3.dot.aspx Thanks, for the response, I'll try it out..
Jun 15 '10 at 11:54 PM
lampshade
That's still buggy, codes shorter though :x
Jun 16 '10 at 02:25 AM
lampshade
Buggy how? What do you need to happen exactly? What are the results you're expecting? What results are you seeing? The only thing I can think of that might be an issue for the "increment if you're moving towards, decrement if you're moving away" is that you might have to special case the player not moving case.
Jun 16 '10 at 04:04 AM
Tetrad
The above "snippet" is a script attached to the player. So transform.position is a position that I control
Jun 16 '10 at 05:02 AM
lampshade
You don't want to do the dot product with the last position, you want to do the dot product with the player's forward velocity vector.
Jun 16 '10 at 05:03 AM
Tetrad
(comments are locked)
|

Not that this helps you at all, but it's spelled "variable".