The directions DO change (incorrectly), and I can't find a pattern with it really. y wasn't what I thought it was, now I'm using .eulerAngles.y instead. You'll have to provide a bit more information for us to understand what exactly you're trying to accomplish here. In that case, rotating by the y component of the quaternion that represents your camera's orientation doesn't make much (any) sense. What type is ? I'm going to guess that it's a quaternion storing the orientation of your camera. Rotation is a linear operation that transforms a vector into a rotated space, which is what the R matrix represents (the identity rotated by theta degrees).ĮDIT2: I'm not exactly sure what .y contains. What did you mean by that? Did it rotate in the opposite direction that you thought it would?ĮDIT: For some justification: the columns of R are the basis vectors of the identity matrix under a rotation of theta degrees. This looks similar to one of your attempts, the one where you said you didn't get "the correct directions". Simply multiply v by R to get the rotated vector. Let v be your vector and R be the rotation matrix. Without even inputting a direction my object moves around in circles and wanders off the scene. Move(new Vector2(Mathf.Sin(directionAngle), Mathf.Cos(directionAngle))) īut EVEN THIS which I was certain would work but was hoping to avoid for inefficiency, is not working at all as expected. I even tried convert the unit vector to degrees, adding the camera's rotation in degrees, and then converting it back into a vector:įloat directionAngle = Mathf.Atan2(Input.GetAxis("P1MoveVertical"), Input.GetAxis("P1MoveHorizontal")) ĭirectionAngle += .y Made a difference, but still not the correct directions. Move(new Vector2((cos * tx) - (sin * ty), (cos * ty) + (sin * tx))) Gives me an error where Quaternion cannot multiply with a vector2.įloat sin = Mathf.Sin(.y) įloat cos = Mathf.Cos(.y) įloat tx = Input.GetAxis("P1MoveHorizontal") įloat ty = Input.GetAxis("P1MoveVertical") (So the joystick direction is a unit vector). Input.GetAxis returns a float from -1 to 1 representing the X position of the joystick. Quaternion.AngleAxis(.y, Vector3.forward) * new Vector2(Input.GetAxis("P1MoveHorizontal"), Input.GetAxis("P1MoveVertical")) Tried multiplying my vector like the following as suggested online: I've done a lot of googling, and couldn't really find what I needed (most similar problems I found were quite a bit more complex).Īlso I'd be calling this up to 4 times per update, so I'm hoping for a solution that isn't horrible on performance. Hopefully someone here can help me.Īs the title says, I have a 2D unit vector, and I simply need to rotate it by X degrees. I've posted this general programming question on other forums, but haven't had much luck.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |