Author Topic: Constrain to Sphere  (Read 1150 times)


  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Constrain to Sphere
« on: April 13, 2015, 07:28:32 PM »
So, here's one that I put together to get a vector3 coordinate constrained within a spherical area... But found out that it has some other uses as well.

This is a beta action so I cannot guarantee it's functionality in every case. Hopefully I will eventually be able to incorporate some error catching and refactoring to make it smoother and easier.

This works by taking a vector point and checking it with two variables... Another vector3 which is the center point of a spherical space and the radius of that sphere. It will then take that vector, get the right location and feed that into another vector.

And a use that I didn't aniticipate... If you've used movement and moved something diagonally, you'll notice that it moves just a hair faster than the strict up/down or left/right movement. I don't fully understand why but I suspect this might be that the vectors are being applied both on the X and Y (or whatever plane you're moving on) fully so there's a bit of over-drive. If you feed that through this action, set the radius to 1 (or whatever you're multiplying in the "Get Axis Vector" action) and the center of the sphere at (0,0,0) you can curb that down so that the horiz and verti are working in tandem.

But here's the action anyway. IF you have any comments, crits, suggestions or corrections, please let me know. I want to be able to up my game in terms of coding but I'm still a nooblet to C#. So, if you see potential problems that could arise, please let me know so I can fix them.