I have a rolling ball player that I have given the ability to dash by pressing a button. The dash works by rapidly spinning the player with transform.Rotate() for a second or so (it's meant to be a purely visual effect, so I didn't use AddTorque()), shooting the player forward using AddForce() with ForceMode.VelocityChange, and rotating the player with decreasing power for another second or so until the dash ends. My problem, however, is that on the ground, the player rolls rapidly during the dash because of friction with the ground (which is good), while in the air, once the rotating stops the player stops spinning due to a lack of friction (which is bad)
I figure that the solution is to set the player's angular momentum at the end of the midair rotation period so the player spins at a plausible speed until they land, but I've been unable to figure out how to properly do this
I've tried AddTorque() and rb.angularVelocity = Xf; and neither achieved the effect I wished (both did next to nothing no matter how high I set the magnitude, and the former moved the player at unpredictable angles to boot)
How can I properly achieve this effect? Am I even looking for the right solution? (Please let me know what - if any - of my code you need to see to properly understand the problem)
#How to instantly set a rolling ball player's angular velocity to a certain speed?
1 messages · Page 1 of 1 (latest)
are you using 2d or 3d, and have you perhaps set rotation constraints?
I am using 3D, I have not set any rotation constraints, and I'm not sure how rotation constraints would be helpful here
im not saying to use constraints, just asking if you have them set (because that would be an issue)
do you need ground friction for anything else? could you just remove friction and do all the spinning manually?
Sorry I'm late, I didn't get a notification... I'd prefer to keep the ground friction as its presence allows the player to slow to a stop naturally when they try to stop moving
angular velocity is a vector, not a single number
so setting it to, say, 10f winds up setting your angular velocity to 10 radians per second in the X/Y/Z axes
perhaps you want to do something like this
rb.angularVelocity = rb.angularVelocity.normalized * 10f;
this would immediately set your anuglar velocity to 10 radians per second in whatever direction you are currently rotating
if you want the rotation to line up with the dash direction, then you need to figure out the correct axis to spin around
If you have a dash direction, you can cross it with the up vector to find a vector to rotate around
Sorry, I oversimplified
I already knew that angular velocity is a vector and have been accounting for that in my code - I just represented the assignment process as rb.angularVelocity = Xf; for brevity
Vector3 crossed = Vector3.Cross(dashVector, Vector3.up);
You may need to negate the result (i'm not sure if this will spin forward or backward)
if you're moving in the +X direction, then you need to spin around the Z axis
note that this is an ill-defined operation if you dash straight up