Hello, I am as green as can be when applying physics to objects and such.
Right now I need help applying physics to a simple office chair.
It looks as such:
Now, I applied a simple Rigibody and Mesh Collider to it, which… Kinda works? But not quite how I want it to be.
Basically what I want is for its weight center to be more at the bottom - where its wheels are. The object should also be fairly heavy, like an office chair normally would be. And besides that, whenever the player pushes into it (just walks into it) it should slowly roll away. So far I’ve accomplished it to fall over and such.
Also, there’s the issue of the player FPSController always walking on top of it, is there a way to stop it from happening? Like, to have kinda like a box mesh attached to it that is always upright, preventing player to step on top of it.
Hello, first of all you should rather create shape approximation of this chair using box colliders instead of mesh collider, for performance reasons(see compound collliders here: Unity - Manual: Rigidbody component reference).
Center of gravity can be set very easily, using this http://docs.unity3d.com/ScriptReference/Rigidbody-centerOfMass.html
Regarding walking on chair- if you want your controller to interact with rigidBodies, you should use physics version of FPS controller(sorry, cant recall what its exact name, but you will find it in standard assets easily).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChairScript : MonoBehaviour
{
public Transform chairPoint;
public float chairRange;
public LayerMask whatIsChair;
public Transform newChairPos;
public GameObject player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.RightAlt)) {
Sit();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChairScript : MonoBehaviour
{
public Transform chairPoint;
public float chairRange;
public LayerMask whatIsChair;
public Transform newChairPos;
public GameObject player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.RightAlt)) {
Sit();
}
}