围绕相对于模型位置和旋转的点旋转
我在Unity(C#)中有一个空间模型,该模型正在跳伞.它始终面向地面,但是X和Z旋转.我要实现的效果是,当我旋转而不是围绕模型中心旋转时,我绕着一个点旋转,该点直接取决于模型向左或向右移动的距离.我已经有了旋转逻辑,但是我没有的是如何确定向右X像素"的世界位置,因为旋转会改变右/左.例如:
I have a model in space in Unity (C#), and this model is skydiving. It's always facing the ground, but X and Z rotate. The effect I'm going for is that when I rotate, rather than rotating around the model center, I rotate around a point a set distance directly to the models left or right, depending. I already have the rotation logic, but what I don't have is how to determine the world position of "X pixels to the right" since rotation changes what is right/left. For example:
当我开始时,左边是-1,0;右边是+1,0 x 我绕左旋转45度.左边仍然是-1,0.但是现在我的位置是(〜)-.7,.7.而且由于我的左"仍然指向-1,0,右突然指向(〜)0,1.4
When I start, left is -1,0; right is +1,0 x I rotate around left 45 degrees. left is still -1,0. But now my position is (~) -.7,.7. And since my "left" is still pointed at -1,0, "right is suddenly pointing at (~) 0,1.4
因此,在给定模型的Vector3位置,模型的X,Z旋转和偏移量的情况下,如何确定向左"和向右"的位置.
So how do I determine, given the model's Vector3 position, the model's X,Z rotation, and the offset, where "to the left" and "to the right" are.
对于那些视觉类型,正当防卫2(Just Cause 2)"做得正确(尽管有时可能很难分辨出来): http://youtu.be/C6H3PPfx1KI?t=2m
For those visual types, Just Cause 2 did it right (though it can be difficult to tell sometimes): http://youtu.be/C6H3PPfx1KI?t=2m
谢谢大家.
听起来您只想执行以下操作:
It sounds like you just want to do the following:
- 在模型空间
left = (-1, 0, 0)
,right = (1, 0, 0)
中分配左/右坐标. - 将旋转点从模型空间转换为世界空间(例如
worldLeft = transform.TransformPoint(left)
). - 绕世界空间点(
transform.RotateAround(worldLeft, Vector3.up, speed * Time.deltaTime)
)旋转.
- Assign left / right coordinates in model space
left = (-1, 0, 0)
,right = (1, 0, 0)
. - Transform rotation point(s) from model space to world space (e.g.
worldLeft = transform.TransformPoint(left)
). - Rotate around world space point (
transform.RotateAround(worldLeft, Vector3.up, speed * Time.deltaTime)
).