gpt4 book ai didi

ios - SpriteKit Physics 的神秘因子 150。重力和力量

转载 作者:行者123 更新时间:2023-11-29 11:49:22 26 4
gpt4 key购买 nike

我想要一个物体漂浮在屏幕上,抵抗重力,根本不动。

这是 View 的重力设置。

    self.physicsWorld.gravity = CGVector(dx: 0, dy: 5.0)

向上设置为 5m/s^2。所以物体每秒向上加速5m

物体的质量设置为1.0kg

    self.physicsBody?.mass = 1.0

我向物体施加了一个力,使其能够抵抗重力。所以我做了以下事情。

func update(delta: TimeInterval) {
...

let force = CGVector(dx: 0.0, dy: -5.0)
self.physicsBody?.applyForce(force)
}

我应用了-5N,因为我认为施加在物体上的重力是1kg * 5m/s^2 = 5N。应用 -5N 将使对象获得 -5m/s^2 的加速度,并在重力作用下漂浮在屏幕上。

但是没有用。相反,我不得不这样做。

    let force = CGVector(dx: 0.0, dy: -5.0 * 150.0)

-5 乘以 150-750。那么,这 150 从何而来?为什么我必须施加 -750N 而不是 -5N 才能使物体抵抗重力?

我还测试了不同重力设置下的不同质量和力。

self.physicsBody?.mass = 2.0
let force = CGVector(dx: 0.0, dy: -5.0 * 150.0 * 2)

self.physicsWorld.gravity = CGVector(dx: 0, dy: 15.0)
self.physicsBody?.mass = 2.0
let force = CGVector(dx: 0.0, dy: -15.0 * 150.0 * 2)

他们都找到了。 F=ma.

问题是150的神秘因素。它到底是从哪里来的?

最佳答案

好吧,这完全是关于 Apple 的错误文档。这是 150 的真相。

this seems to be little bit stupid, but applyForce is measured in ((points * kilo) / sec ^ 2), but the gravity acceleration is in Newtons ((kilo * meter)/ sec ^ 2) (despite the fact it's described as meters per second in documentation. Meters per second! Acceleration!). Multiply it by mass and get the force.

https://stackoverflow.com/a/31868380/5752908

拜托,Apple...它已经推出 4 年了。

关于ios - SpriteKit Physics 的神秘因子 150。重力和力量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41876194/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com