- Home /
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 :)
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!
we need $$anonymous$$r Turing to tell us eh ! :)
good point on combining rotations. perhaps good advice for beginners is "stick with .Rotate until you get to the point of needing to combine rotations"
To clarify my point: I believe there's an effect where beginners happen to see certain "advanced terms" and they incorrectly think those advanced concepts are necessary to achieve something very simple.
(I think there was an example yesterday. I think someone just needed to know how to get a random number ("Random.Range(1,7)") but, incorrectly though they had to do something with mersenne twisters or the like.)
There should be a term for this phenomenon! Where someone trying to solve a software problem (where, in fact, a trivial commonplace high-level solution exists today) is distracted by an arcane term and incorrectly thinks they must learn about / work at a much lower, more complex, level.
(I was guilty of a somewhat similar thing the other day, I thought a client wanted a whole sort of server-based social interaction system. I had utterly misunderstood, all they wanted was a button in the app that opened a browser with a certain URL !! :O )
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("$$anonymous$$ouse X") xSpeed 0.02; y -= Input.GetAxis("$$anonymous$$ouse Y") ySpeed 0.02;
y = ClampAngle(y, y$$anonymous$$inLimit, y$$anonymous$$axLimit);
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
Answer by whydoidoit · Mar 31, 2013 at 10:34 AM
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.
Your answer
Follow this Question
Related Questions
Perpendicular Vector3 0 Answers
c# modify only one axis of a quaternion 2 Answers
Unity's equivalent of Vector3.Transform(...) 2 Answers
How Make an Vector Follow an Quaternion? 1 Answer
Help with Quaternions and Vector3s 2 Answers