How to imitate inertia without a Rigidbody or how to disable Boxcollider's physics?
Aim is to rotate an Object around a pivot point on player's input, rotation should have some kind of inertia.
Problem: when setting Box collider, RigidBody.AddTorque rotation method changes the center of rotation from pivot to Box collider's center of mass (i think). Setting centerOfMass manually in script didn't help.
Transform.RotateAround works perfectly fine with Box collider, but i couldn't find a way to imitate inertia w/o GameObject interacting with physics (Rigidbody+apply physical impact).
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private GameObject player;
private Rigidbody playerRb;
[SerializeField] private float turnSpeed;
public Transform customPivot;
void Start()
{
player = GetComponent<GameObject>();
playerRb = GetComponent<Rigidbody>();
}
void Update()
{
float leftRightInput = Input.GetAxis("Horizontal");
//Works with BoxCollider but no physics applied
transform.RotateAround(customPivot.position, Vector3.forward, turnSpeed * leftRightInput);
//Physics applied but BoxCollider ruins rotation around pivot
playerRb.AddTorque(new Vector3(0, 0, turnSpeed) * leftRightInput, ForceMode.Acceleration);
}
}
Is there a way to disable Box collider's physics (why does it even affect game object's physics?) or is there a way to apply inertia while using transform.Rotate (w/o Rigidbody)?
Looking forward to get any information on the topic, it's been a while since i've been trying to solve this puzzle.
Your answer
Follow this Question
Related Questions
2D Physics - Inertia and inherited motion. 1 Answer
Attaching Prefabs between them 0 Answers
Rotate player around enemy (Lock system) 1 Answer
Make pivot transition in mecanim in a 2.5d game? 0 Answers
RectTransform Pivot versus the Blue Dot. 0 Answers