- Home /
How to move a rigidbody along a curve or spiral
I'm trying to get a rigidbody to spin in a spiral or a curve much like this:
The game is in 3d but this is just a 2d representation. The arrow in the circle represents the way the rigidbody is facing.
I've tried many things and got fairly close.
RotateAround seemed to be a good solution. The problem was that this force needs to be relative to the rigidbody's position and rotation. When using RotateAround, the rigidbody always circled around the same point regardless of rotation.
AddTorque was strange. It seemed like the rigidbody couldn't rotate in two directions at once. I added torque to the Y axis and then added force to the rigidbody. It rotated just fine on the Y axis, but the x and or z axis did nothing when the rigidbody started moving forward. I feel like the ball should have done something similar to the picture but it just went in a straight line and rotated on the Y axis at the same time. The rigidbody rotates forward normally without that specific torque added to it strangely enough.
AddForce was another close one for me. I used AddRelativeForce to a point to the right of it every FixedUpdate which did some strange things. The ball would sometimes bounce even though all force was on the x and y axes and it took place on 1 level plane added to the scene. It also didn't follow a smooth path most of the time. Depending on the destination of this point and the amount of force I had pulling it, it would usually go in a jagged curve, bounce, and most of the time pick up speed and fly away into the distance even though that point was only a few units to the right of the rigidbody.
Here's one of the lines of code I tried to get this working:
rigidBody.AddRelativeForce ((transform.right + new Vector3 (distance1, 0, distance2)) * spinMultiplyer * force);
force -= forceMinus;
In this particular example, I tried reducing force by "forceMinus" which was very small, usually .002 to .006. I also tried keeping force constant and having forceMinus = 0. I also made all the variables public so I could change them in game to try and find a good result, but after hours and hours of trying, I've decided that I probably need help. I've looked at many different questions about a similar topic and tried the solutions provided, but none seemed to satisfy my problem.