使用物理学扔物体?(统一)

编程入门 行业动态 更新时间:2024-10-23 04:53:03
本文介绍了使用物理学扔物体?(统一)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以,我已经工作了 4 个多小时,我正在尝试制作一个玩家可以扔的物体.我想扔它,(不要扔得太远,比如 0.5 米,)但我似乎无法得到它.我尝试通过刚体添加力,制作动画,并仅更改其变换.如果有人必须做类似的事情,有人可以帮助我吗?如果是,你是怎么做的?

So, I have been working for 4+ hours now, and I am trying to make an object that the player can throw. I was thinking of like tossing it, (not throwing it far, like .5 meters,) and I can’t seem to get it. I have tried adding force through rigidbody, making an animation, and just changing its transform. Can anyone help me if has anyone had to do something similar, if so how did you do it?

我没有任何代码示例,因为没有任何效果.(请不要只说刚体,你能举个例子吗.谢谢.)

I don’t have any code examples, because nothing worked. (Please don’t just say Rigidbody, can you give examples. Thanks.)

推荐答案

由于声誉原因,我仍然无法添加评论,因此这里是设置基于鼠标输入抛出的刚体的通用方法.

I am still unable to add comments due to reputation, so here is a generic approach to setting up a rigidbody to be thrown based on mouse input.

Camera cam; Rigidbody r; Vector3 direction = cam.ScreenPointToRay(Input.mousePosition); r.AddForce(direction * 100);

代码使用场景的相机,要抛出的物体的刚体,然后将鼠标输入的屏幕空间转换为光线投射以获得抛出物体的方向,然后在那个方向的那个物体.

The code is using the camera of your scene, the rigidbody of the object you want to throw, it then converts the screen space of the mouse input to a raycast to get a direction to throw the object, then adds a force on that object in that direction.

如果您的代码看起来像这样,则很有可能您正在其他地方更改对象的速度或变换.它也可能与另一个物体发生碰撞并被停止.

If you code looks something like this, there is a good chance you are changing the velocity or transform of the object elsewhere. It could also be colliding with another object and be getting stopped.

更多推荐

使用物理学扔物体?(统一)

本文发布于:2023-06-04 19:09:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/503358.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:物理学   物体

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!