如何添加随机“模糊”?到这个公式,以便随机性随着值的增加而减少?

发布于 2024-10-09 04:29:47 字数 511 浏览 7 评论 0原文

我正在开发一款开放式策略游戏。我使用以下公式来计算伤害:

$rand = rand($a, $b) + $c;
$damage = $rand * sqrt(($d / 20) * $c));

$a$b$c$d是用户在游戏过程中可以修改的所有值,可以通过购买更好的物品($a$b)、投资该物品(< code>$c),或者投资他们的角色$d

我现在想做的是为方程的结果添加一点随机性。然而,由于游戏是开放式的:

  1. 随着时间的推移,静态值将变得不明显/可以忽略不计。
  2. 基于百分比的值会随着时间的推移而产生过多的噪音。

因此,我想添加一个随机值,该值一开始很小,随着输入的增加而增长,但收益递减。我确定我需要某种对数公式,但我不知道如何去做!

I'm developing an open-ended strategy game. I am using the following formula to calculate damage:

$rand = rand($a, $b) + $c;
$damage = $rand * sqrt(($d / 20) * $c));

$a, $b, $c, and $d are all values that can be modified by the user over the course of play, either by buying a better item ($a and $b), investing in the item ($c), or investing in their character $d.

What I want to do now is add a bit of randomness to the outcome of the equation. However, because the game is open ended:

  1. a static value would become unnoticeable/negligible over time.
  2. a percentage based value would allow for too much noise over time.

So, I want to add a random value that is small at first, grows with increased input, but has diminishing returns. I'm sure I need some kind of logarithmic formula, but I'm not sure how to go about it!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失眠症患者 2024-10-16 04:29:47

如果你计算你的原始伤害,因为 D 和 R 在 [-1,1] 中是随机的,那么你有很多选择。你不想要静态:

D = D + 1 * constant * R

或百分比

D = D + D * constant * R.

之间的东西可能是

D = D + sqrt(D) * constant * R.

常数和线性之间的任何 D 函数都会给你一个不同的平衡。

If you calculate your original damage as D and R is random in [-1,1], you have lots of options. You didn't want static:

D = D + 1 * constant * R

or percentage

D = D + D * constant * R.

Something in between might be

D = D + sqrt(D) * constant * R.

Any function of D between constant and linear will give you a different balance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文