- Home /
Question by
Like80ninjas · Dec 06, 2020 at 09:13 PM ·
physicscharactercontrollercharacter movement
Calculating linear speed at a point on a rotating platform
I'm working on a system for moving platforms without rigidbodies and with parenting.
I'm trying to keep the player rotating with a platform while standing on it, but getting slower the further it gets from the center - matching the platforms angular speed.
What I have now is rotating the character around the platform, and changing the speed based on the distance from center and speed of the rotating platform... but it's just not correct. The player either rotates too slow or too fast, etc.
Can anyone help me figure out what I'm doing wrong?
Here is my code:
private void LateUpdate()
{
if (CurrentPlatform != null)
{
var movingPlatform = CurrentPlatform.GetComponent<MovingPlatform>();
if (movingPlatform != null)
{
if (movingPlatform.IsRotating)
{
var savedRotation = transform.eulerAngles;
var radius = Vector3.Distance(transform.position, CurrentPlatform.transform.position);
var linearSpeed = radius * (movingPlatform.AngularSpeed);
var platformRotationAxis = movingPlatform.GetLocalRotationAxis();
transform.RotateAround(CurrentPlatform.transform.position, platformRotationAxis, linearSpeed * Time.deltaTime);
transform.eulerAngles = savedRotation;
}
}
}
}
Comment