Last active
May 22, 2020 09:29
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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