Hello. I am a 3D Modeler in Unity and I created a lantern with a chain. Each link has a hinge joint, rigid body and a collider.
I am trying to program the lantern to naturally sway in the wind? I am not a programmer by any means, but my teacher said to create a basic code to apply a force to the rigid bodies, and I created a code that looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LanternForce : MonoBehaviour
{
public float thrust;
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.AddRelativeForce(Vector3.forward * thrust);
}
}
The code works, but the lantern is blown to the ceiling and staying there.
According to my teacher, the lantern is having a force constantly applied to it, making blown onto the ceiling every second. But yet she wouldn’t tell me how to fix it.
How can I modify the code to have a random force applied to it, and to make it blow “sideways” instead of “forward”, to create a natural swaying motion in the wind?