Object Rotation With Touch
Hey guys,
Can i have some help with this object rotation please, been at it for hours and 3d math is no way my strongest point as a programmer.
Atm im trying to rotate an object with touch input but have it clamped so that it cannot go past a certain value. The point of this rotation is too just rotate the cube enough so you can just nearlly see the extra sides of it or the back of it.
When you press on the screen it should not snap back it should take the rotation it already had and go from there. This has honestly been the bane of my life and my brain is melting with it right now.
I attached a pic to show what i mean. It must stay at this current angle and only rotate left and right.
Please lend us a hand with this.
Cheers fellas
John
: Code - Butchered from answers, been through so many iterations (My own, answers, google + more)
using UnityEngine;
using System.Collections;
public class DragRotateSlowDown : MonoBehaviour {
private float rotationSpeed = 10.0F;
private float lerpSpeed = 1.0F;
private Vector3 theSpeed;
private Vector3 avgSpeed;
private bool isDragging = false;
private Vector3 targetSpeedX;
void OnMouseDown() {
isDragging = true;
}
void Update() {
if (Input.GetMouseButton(0) && isDragging) {
theSpeed = new Vector3(-Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0.0F);
avgSpeed = Vector3.Lerp(avgSpeed, theSpeed, Time.deltaTime * 5);
} else {
if (isDragging) {
theSpeed = avgSpeed;
isDragging = false;
}
float i = Time.deltaTime * lerpSpeed;
theSpeed = Vector3.Lerp(theSpeed, Vector3.zero, i);
}
transform.Rotate(Camera.main.transform.up * theSpeed.x * rotationSpeed, Space.World);
transform.Rotate(Camera.main.transform.right * theSpeed.y * rotationSpeed, Space.World);
}
@john-essy Did you get the solution for this, If so please share with the community
Thanks