Hello all,
I’m attempting to create a simple game where the player uses the mouse to manipulate the tilt angles of a table on which a bill rolls (a rolling marble game). When I scripted the table to tilt directly relative to mouse position, I ran into a problem where the table moved too fast for the collision detection and the sphere passes through the surface (and drops int the void). I need a method similar to Rigidbody.MovePosition that works on angular rotation. I tried using Rigidbody.angularVelocity, but the physics engine seems to ignore it [code below].
Anyone out there try to do this? My alternative is to try and write my own code to .manage the rotation angular velocity, but that would be tedious and unnecessary if there is a method out there that would do this for me.
THanks in advance.
/Philip
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GroundTilt : MonoBehaviour
{
public Text statusText;
public float scaleFactor;
public float dampeningFactor;
private Rigidbody rb;
private Vector3 initMousePos,targetRotation,offset;
// Start is called before the first frame update
void Start()
{
statusText.text = "";
initMousePos.y = 0;
rb = gameObject.GetComponentInParent<Rigidbody>();
//GetComponentInParent<Rigidbody>();
}
private void OnMouseDown()
{
initMousePos = new Vector3 (Input.mousePosition.y,0, -Input.mousePosition.x) * scaleFactor;
targetRotation = new Vector3(0,0,0);
//statusText.text = "Mouse Down " + targetRotation;
}
private void OnMouseDrag()
{
Vector3 currentPosition = new Vector3((Input.mousePosition.y), 0, -Input.mousePosition.x) * scaleFactor;
targetRotation = currentPosition - initMousePos;
}
private void FixedUpdate()
{
offset = (targetRotation - (gameObject.transform.eulerAngles * Mathf.Deg2Rad)) * dampeningFactor;
rb.angularVelocity = offset;
statusText.text = "Angular Velocity" + rb.angularVelocity;
//statusText.text = rb.name;
}
// Update is called once per frame
void Update()
{
}
}