Skip to content

Instantly share code, notes, and snippets.

@aibekn
Last active May 22, 2020 09:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save aibekn/1a2a8acc7602f40ca6deb7cd4dc0c66e to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotatableObject : MonoBehaviour
{
// rot Speed 8100f
public float rotationSpeed = 8100f;
bool dragging;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
//joystick = FindObjectOfType<Joystick>();
rb.centerOfMass = Vector3.zero;
rb.inertiaTensorRotation = Quaternion.identity;
}
void Update()
{
if( Input.GetMouseButtonDown(0) ){
dragging = true;
}
if( Input.GetMouseButtonUp(0) ){
dragging = false;
}
}
void FixedUpdate(){
if( dragging ){
// As in PolySphere game, Torque
float rotX = Input.GetAxis("Mouse X") * rotationSpeed * Mathf.Deg2Rad * Time.fixedDeltaTime;
float rotY = Input.GetAxis("Mouse Y") * rotationSpeed * Mathf.Deg2Rad * Time.fixedDeltaTime;
rb.AddTorque (Vector3.down * -rotX);
rb.AddTorque (Vector3.right * rotY);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment