- Home /
The problem was resolved by what is mentioned in the EDIT part of the question.
How to alter a script from the forum?
Hi guys.I feel silly for asking this but i have tried to solve it my self for a week now and i haven't gotten anywhere. For my game I found a c# script by Jesse Anders here on the forums:http://forum.unity3d.com/threads/86174-Rotating-object-on-2-axis. It is for rotating a game object around 2 axis.
The first time I found this I managed to alter the script so that it works how i want it but after my laptop crashed and I lost all my work I've been trying to alter it again but without any success.
The problem is the script rotates the game object automatically by 90 degrees when the game just starts and I want the game object to rotate only if input has been detected.I know that the part responsible is in the start function but when i remove it from the start function I receive errors or the game only accepts one input and no more after that.
Should a part of the code go into the Update function or should the for loop be altered in any way?
Any help towards altering the script would be much appreciated as I feel I am constantly missing something simple which I got the first time i altered the script. Here is the sample of the code in the start function.
void Start()
{
Quaternion[] rotations = new Quaternion[]
{
Quaternion.AngleAxis(-90, Vector3.up),
Quaternion.AngleAxis(90, Vector3.up),
Quaternion.AngleAxis(-90, Vector3.right),
Quaternion.AngleAxis(90, Vector3.right)
};
for (int i = 0; i < 24; ++i)
{
for (int j = 0; j < 4; ++j)
{
var currentOrientation = rotations[j] * orientations[i];
float maxDot = 0f;
int neighborIndex = 0;
for (int k = 0; k < 24; ++k)
{
float dot=Mathf.Abs(Quaternion.Dot(currentOrientation,orientations[k]));
if (dot > maxDot) {
maxDot = dot;
neighborIndex = k;
}
}
neighborIndices[i, j] = neighborIndex;
}
}
transform.rotation = orientations[orientationIndex];
}
EDITED: In the end I just used a different script that works just fine and required minimum tweaking.Thank you all.
you are really best to ask on the forum. is there a chance you could edit your code here so it does not have unnecessary newlines? thx
Just cleaned up the code.It pasted badly sorry for that. I did post a question on the thread several days ago but so far no reply and the thing is the thread is several years old,so I'm not sure if anyone who originally took part in the discussion still checks it.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Disabling a script in c# not working for some reason 1 Answer
Same GUI script showing up in different places 0 Answers
C# Movement Script 0 Answers