Quaternion and Vector3

I am lost on why i get

‘Assets/Scripts/Move_Camera.cs(42,67): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected’

With the following code - I am still new to Unity so be gentle :slight_smile:

Quaternion Targetrotation = Quaternion.Euler(y, x, 0);
Vector3	Targetposition = Targetrotation * Vector3(Targetrotation) * Vector3(0.0, 0.0, -distance) + target.position;

Vector3(TargetRotation) will not work because the Vector3 constructor doesn't take Quartenion as parameters. Vector3(0.0, 0.0, -distance) will not work because it is missing the new keyword.

there is something to be said for simply not using Quaternions at all, ever, unless you have a lot of expertise with them. Be sure to look at the super-simple and amazing commands .Rotate and also the very handy .RotateAround (I'm intrigued by the question, can one do everything without every using Quaternions? I don't know.)

Quaternions are very handy when you want to combine rotations - like orient an object's up to a surface normal etc. Harder to do that with Eulers, quite possibly not possible!

Thanks for the comments - actually this is a convert from JS to C# here is the full piece - that works function LateUpdate () { if (target) { x += Input.GetAxis("Mouse X") * xSpeed * 0.02; y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02; y = ClampAngle(y, yMinLimit, yMaxLimit); var rotation = Quaternion.Euler(y, x, 0); var position = rotation * Vector3(0.0, 0.0, -distance) + target.position; transform.rotation = rotation; transform.position = position; } }

The conversion would then be: void LateUpdate () { if (target != null) { x += Input.GetAxis("Mouse X") * xSpeed * 0.02f; y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; y = ClampAngle(y, yMinLimit, yMaxLimit); transform.rotation = Quaternion.Euler(y, x, 0); transform.position = transform.rotation * new Vector3(0, 0, -distance) + target.position; } }

2 Answers

2

Firstly it’s the lack of new as @Kolkina says. Your next problem is that you are trying to multiply Vector3s - you can’t do that. And you certainly can’t do Vector3(TargetRotation) - what does that mean?

I think what you want to do is:

var targetPosition = (targetRotation * Vector3.forward * distance) + target.position; //or maybe - distance

Vector3.forward is (0,0,1). You can multiple the quaternion by the vector and the vector by the scalar.