- Home /
Mouse drag bad rotation
Hey, so I have this script set up to rotate my cam pivot when i drag the screen with the mouse and encontered an issue i wasn't able to fix, my cam rotates on the z axis and completely ruins everything xD I wondered if someone could help me getting this script working fine and maybe upgrade it a bit ( i know it is kind of a rude method of changing rotation xD ) Anyways, thanks for reading
void Update()
{
transform.position = player.transform.position;
if (Input.GetMouseButtonDown(0)) {
PressPoint = Input.mousePosition;
StartRotation = transform.rotation;
}
else if (Input.GetMouseButton(0)) {
Vector3 CurrentDistanceBetweenMousePositions = new Vector3(-(Input.mousePosition - PressPoint ).y, -(Input.mousePosition - PressPoint ).x, 0);
transform.rotation = StartRotation * Quaternion.Euler( CurrentDistanceBetweenMousePositions /
SceneWidth * 360);
}
Answer by zORg_alex · May 25 at 07:38 AM
You should play with multipliers.
public float RotationMultiplier = 360;//As you have now
...
transform.rotation = StartRotation * Quaternion.Euler( CurrentDistanceBetweenMousePositions /
SceneWidth * RotationMultiplier );
Play with that parameter to find out what is the best for you.
The script itself is kind of wonky, but it should do.
I've personally stopped using legacy Input class, I switched to a new InputActions. But you need to dig it. First you need to install that package InputActions, second you'd need to switch project settings to use both piplines, since you probably have a ton of legacy Input, so it will be a pain to do at once, plus all scripts you get from internet and assets are probably still are using only legacy Input. Then create either an asset with all inputs you'd listen to or create them dynamically in code or in editor for every script. It seems like a hassle, but using legacy Input for multiple players/gampads/mice/keyboards... Is even more hassle. So for prototypes I use a code creation of InputActions.
Your answer
Follow this Question
Related Questions
Step/Iterative Debugging 1 Answer
How to catch Unity values in Android EDI ? 0 Answers
Getting variables from c# to js 2 Answers
Debug a DLL that's loaded by a Unity program. 0 Answers
Could the game crash be a GC problem? 0 Answers