围绕相对于模型位置和旋转的点旋转 [英] Rotating around a point relative to model position and rotation

查看:190
本文介绍了围绕相对于模型位置和旋转的点旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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:

  1. 在模型空间left = (-1, 0, 0)right = (1, 0, 0)中分配左/右坐标.
  2. 将旋转点从模型空间转换为世界空间(例如worldLeft = transform.TransformPoint(left)).
  3. 绕世界空间点(transform.RotateAround(worldLeft, Vector3.up, speed * Time.deltaTime))旋转.
  1. Assign left / right coordinates in model space left = (-1, 0, 0), right = (1, 0, 0).
  2. Transform rotation point(s) from model space to world space (e.g. worldLeft = transform.TransformPoint(left)).
  3. Rotate around world space point (transform.RotateAround(worldLeft, Vector3.up, speed * Time.deltaTime)).

这篇关于围绕相对于模型位置和旋转的点旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆