Hey there,
I’ve been trying to get a swinging system to work for the past 3 weeks.
I’ve seen several tutorials that use Spring Joints, but that doesn’t work well with Character Controller and my player always ends up falling through collision when the spring joint is activated.
So I’m trying to use the pendulum equation to achieve the swing movement but it totally not working.
I don’t know if this is the right way to make a swing system so I’m hoping someone can help me with how to fix this or what other technique I should use.
// Update is called once per frame
void Update()
{
Vector3 velocity = (transform.position - previousPosition) / Time.deltaTime;
previousPosition = transform.position;
float dot = Vector3.Dot(velocity, transform.position - anchorPoint.transform.position);
Vector3 normalize = Vector3.Normalize(transform.position - anchorPoint.transform.position);
swingMovement = ((normalize * dot) * -2f);
Vector3 gravity = Vector3.down * 9.81f * Time.deltaTime;
character.Move((gravity + swingMovement) * Time.deltaTime);
}