#How to instantly set a rolling ball player's angular velocity to a certain speed?

1 messages · Page 1 of 1 (latest)

remote valve
#

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)

viscid wagon
remote valve
viscid wagon
#

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?

remote valve
hardy sleet
#

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

remote valve
hardy sleet
#
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