use blender kit search a chest model
blender - separate lid and body
select all the faces of lid then separate them.
to do animation of chest, the pivot point should put on the hinged edge (place your 3d cursor to middle hinged edge)
object mode >> object >> set origin >> origin to 3d cursor
open animation tab
on the record button
select the object then insert keyframe
Right click the object, insert keyframe
Go to new timeline
Click R to rotate, press x to rotate x axis
Then right click insert keyframe.
export your fbx and make sure it on the animation checkbox
Unity Open Chest
youtube - open chest
Import your chest animation to unity
drag your animation to the animator editor
Add your chest open animator to controller.
now you can test your chest open animation in unity game engine. But, now we still do not have paramter to control the chest open when the player near to it
in my youtube video , i accidently connected to exit state. if we want our chest after play the animation then end and let the chest open after we pickup the items.
we use Trigger parameter as trigger is easy and it is trigger the every time the parameter is called in script
Name the parameters as "chestOpen", this parameter name should same with script
animator.SetTrigger("chestOpen");
Select this arrow, in conditions there select chestOpen
attach your script to chest
using UnityEngine;
public class Chest : MonoBehaviour
{
private Animator animator;
//private bool isOpened = false;
void Start()
{
animator = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
animator.SetTrigger("chestOpen");
//isOpened = true;
}
}
}
Add collider to your chest
Add component >> box collider
isTrigger checkbox is true
edit your collider
you can make it bigger a bit
your chest's inspector is look like this
when the player is approaching the chest, the chest will open.