Hi, this is my first post on this site and I’m a complete beginner to Scripting, so I need your help please!
I found/modified the code below to allow for the mouse to drag and rotate an object.
It works perfectly on the Built-In assests, but when Import my own Assets from Cinema 4D, add the Script Component to the Imported Assest, nothing happens.
Do I need to adjsut something for Mesh objects? I tried placing the imported assest as a Child of an Empty Game Object, but still no movement when Playing the scene.
**Edit: my problem might be with Mesh objects. Every Script I write works with built in Assests, but not my imported Meshes :S
Thanks in advance
var rotationSpeed = 10.0;
var lerpSpeed = 6.0;
private var speed = new Vector3();
private var avgSpeed = new Vector3();
private var dragging = false;
private var targetSpeedY = new Vector3();
function OnMouseDown()
{
dragging = true;
}
function OnMouseUp()
{
dragging = false;
}
function Update ()
{
if (dragging) {
speed = new Vector3(-Input.GetAxis ("Mouse X"), Input.GetAxis("Mouse Y"), 0);
avgSpeed = Vector3.Lerp(avgSpeed,speed,Time.deltaTime * 5);
} else {
if (dragging) {
speed = avgSpeed;
dragging = false;
}
var i = Time.deltaTime * lerpSpeed;
speed = Vector3.Lerp( speed, Vector3.zero, i);
}
transform.Rotate(Vector3.up, speed.x * rotationSpeed, Space.World);
transform.Rotate(Vector3.forward, speed.y * rotationSpeed, Space.World);
transform.Rotate(Vector3.right, speed.y * rotationSpeed, Space.World);
}