Unity 瞄准辅助
我正在创建一个统一的 3D 自上而下射击游戏,并希望为其创建一个瞄准辅助,因为击中敌人很困难。我的想法是创建一个触发器,当玩家瞄准敌人时,减慢武器上操纵杆的旋转速度。我按如下方式实施轮换:
float eulerY = (Mathf.Atan2(_JoystickShoot.Direction.x, _JoystickShoot.Direction.y) * 180 / Mathf.PI);
但是,我现在不知道如何实施减速。玩家的旋转速度应慢于操纵杆的实际旋转速度。 到目前为止,我的方法还没有真正成功。 有人知道吗?
谢谢 :)
i am creating a 3d top down shooter with unity and wanted to create an aim assist for it since hitting enemies is difficult. my idea was to create a trigger that slows down the rotation of the joystick on the weapon when the player aims at an enemy. i implement my rotation as follows:
float eulerY = (Mathf.Atan2(_JoystickShoot.Direction.x, _JoystickShoot.Direction.y) * 180 / Mathf.PI);
However, I don't know how to implement the slowdown now. The player should rotate slower than the actual rotation of the joystick.
My approaches have not really been successful so far.
does anyone have any idea?
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以添加一个缩放旋转的变量。将其设置为 1,除非当您指向敌人时,您可以将其设置为 0 到 1 之间的值,让您感觉良好。
如果您想将十字准线拉向敌人,您可以计算与最近敌人的角度(或距离)。如果低于某个阈值,您可以调整旋转功能,以有利于朝向敌人的旋转而不是远离敌人的旋转。您可以使用这样的东西:
您也可以针对多个角度进行调整,但仅对 X 和 Y 方向进行相同的计算可能会感觉有点尴尬。原因是,在这种情况下,您必须将其与“真实”角度/距离进行比较,而不是单独与 X 和 Y 角度/距离进行比较。
You can add a variable that scales the rotation. Set it to 1, except when you're pointing at an enemy, where you set it to a value between 0 and 1 that feels good for you.
If you want to draw the crosshair towards an enemy, you can calculate the angle (or distance) to the closest enemy. If it is below a certain threshold you can adjust your rotation function to favor rotations towards the enemy over rotations away from it. You can use something like this:
You can adjust this for multiple angles as well, but just doing the same calculation for X and Y direction might feel a bit awkward. The reason is that in that case you have to compare it against the "true" angle/distance, not against the X and Y angles/distances individually.
我认为谈论“方向”比谈论“旋转”更有用。
假设您的飞船沿着与操纵杆指向相同的方向行驶和/或射击。这是一种自然且直观的关系。 “减慢旋转速度”很可能会打破这一点,使您的界面使用起来不太直观。通常也有直接从方向向量到旋转的方法,例如 Quaternion .LookRotation,避免直接处理角度。
您可以检查小弧内是否有任何敌人,选择最靠近弧中心的敌人,然后使用朝向该敌人的方向开火。请注意,如果敌人正在移动且射击速度缓慢,则这可能会失败,因为它会阻止你“领先”你的投篮。
其他选择可能只是让你的敌人更容易被击中。使敌人或射击更大,或者可能只是使命中框更大。或者增加射速和/或分散性。
I think it is more useful to talk about 'direction' rather than 'rotation'.
Presumably your ship travels and/or shoots in the same direction as the joystick is pointing in. This is a natural and intuitive relationship. "slowing down rotation" will most likely break this, making your interface less intuitive to use. There are also usually ways to go directly from a direction-vector to a rotation, for example Quaternion.LookRotation, avoiding the need to deal angles directly.
You could instead check if there is any enemy within a small arc, select the enemy closest to the center of the arc, and use the direction towards that enemy to fire in. Note that this can fail if enemies are moving and shots are slow, since it can prevent 'leading' your shots.
Other alternatives could be to simply make your enemies easier to hit. Make the enemies or shots larger, or possibly, just make the hitboxes larger. Or increase fire-rate and/or dispersion.