Hi guys,
in the function Spin, I am basically making the sum of 2 Vector3, but for whatever reason the compiler returns me that ‘+ can’t have left hand a vector and right and an object’ error, which I don’t think it’s true but can’t see it… the error should be in the FOR at the bottom of the function. Many thanks for the help.
for (dir in previousDirList) {
avgPreviousDir = avgPreviousDir + dir;
}
function Spin (dir : Vector3) {
var hit : RaycastHit;
var previousDirList : Array = new Array ();
var currentDir : Vector3;
// Initialize previous dir list
for (var i : int = 0; i < numberAverages; i++) {
previousDirList.Add (currentDir);
}
currentDir = dir;
// Make the object rotate with the cursor while we are grabbing it
while (Input.GetButton ("Fire1") Physics.Raycast (camera.main.ScreenPointToRay(Input.mousePosition), hit)) {
// Remove first element of the array
previousDirList.RemoveAt (0);
// Add current dir to the end
previousDirList.Add (currentDir);
currentDir = hit.point - transform.position;
transform.rotation = Quaternion.LookRotation (currentDir) * offsetRotation * originalRotation;
yield;
}
// User let go of the mouse so make the object spin on its own
var avgPreviousDir : Vector3 = Vector3.zero;
for (dir in previousDirList) {
avgPreviousDir = avgPreviousDir + dir;
}
avgPreviousDir /= numberAverages;
Kick (currentDir, avgPreviousDir);
}