简体   繁体   English

将对象返回其原始旋转和高度统一C#

[英]Return an object to its original rotation and height unity C#

I want to allow a boat in my 3D simulation of a ship to rotate and be moved on all axes. 我想让我的船的3D模拟中的船旋转并在所有轴上移动。 However, the way that I have the boat's movement programmed makes this impossible. 但是,按照我对船的运动进行编程的方式,这不可能实现。

The way it moves: 它的移动方式:

this.transform.Translate(Vector3.left * Time.smoothDeltaTime * speed);

The way it turns: 转变的方式:

this.transform.Rotate(Vector3.forward * Time.smoothDeltaTime * (int)horizontal)

The shape of the boat also makes it impossible to simply move it on a solid base, since it does have the triangular shape (for underwater collisions). 船的形状也使它不可能简单地在坚固的基座上移动,因为它确实具有三角形的形状(用于水下碰撞)。

So what I want to do is allow the boat to be affected by gravity, but still float on the water. 所以我想做的是让船受重力影响,但仍漂浮在水面上。 Then, when the boat hits something, it needs to be able to "roll" and then eventually return to its normal position. 然后,当船撞到某物时,它需要能够“滚动”,然后最终返回其正常位置。

So, is there any way to make an object slowly return to its normal rotation(z rotation of 0) after it hit something, and not be affected by gravity once it reaches a certain elevation. 因此,有什么方法可以使物体撞击到物体后缓慢返回其正常旋转(z旋转为0),并且一旦达到一定的高度就不会受到重力的影响。 (Y value of 34.75) (Y值34.75)

The boat has a Rigidbody and a Mesh Collider 船上有一个刚体和一个对撞机

I'm not sure if the player would be able to move when he gets hit, but you could save the current values to local variables (for example: Transform transformOnHit ). 我不确定玩家被击中时是否能够移动,但是您可以将当前值保存到局部变量中(例如: Transform transformOnHit )。 After you complete the roll, you can use your own provided code to translate and rotate back to the original transform. 完成滚动后,您可以使用自己提供的代码来平移并旋转回原始转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM