球不滚动

问题描述 投票:0回答:1

在 Apple VisionOS 中我已经奠定了基础:

if let floor = scene.findEntity(named: "Sol")
{
    floor.components[PhysicsBodyComponent.self] = .init(
        massProperties: .default,
        material: .generate( staticFriction: 1, dynamicFriction: 0.5, restitution: 0),
        mode: .static)
    floor.generateCollisionShapes( recursive: false)
    floor.components.set( ImageBasedLightComponent(source: .single( environmentLight!)))
    floor.components.set( ImageBasedLightReceiverComponent( imageBasedLight: floor))
}

和一个球:

if let sphere = scene.findEntity(named: "Boule_Chrome")
{
    Set_Entity_Params( entity: sphere, mass: 0.70, friction: kBoules_Friction, rebond: 0.0005, ralentissement: 1)
    sphere.components.set( ImageBasedLightComponent(source: .single( environmentLight!)))
    sphere.components.set( ImageBasedLightReceiverComponent( imageBasedLight: sphere))
}
.

..

func Set_Entity_Params( entity: Entity, mass: Float, friction: Float, rebond: Float, ralentissement: Float, mode: PhysicsBodyMode = .dynamic)
{
    entity.components.set( InputTargetComponent())// Permet d'etre saisisable à la main
    entity.components.set( GroundingShadowComponent(castsShadow: true))

    var spherePhysics = PhysicsBodyComponent( massProperties: .init(mass: mass), material: .generate(staticFriction: friction, dynamicFriction: friction, restitution: rebond), mode: mode)
    spherePhysics.isRotationLocked = (x:false, y:false, z:false)
    spherePhysics.isContinuousCollisionDetectionEnabled = true
    spherePhysics.angularDamping = 0.9 
    spherePhysics.linearDamping = ralentissement 
    entity.components.set( spherePhysics)
}

要将球发射到地面上,我只需应用线速度:

sphere.components[PhysicsMotionComponent.self]?.linearVelocity = SIMD3<Float>(0, 0, -7.8)

一切都很完美,球发射出去,接触地面并在地面上移动,那就完美了。 除了球在地上不是滚动,而是滑动

有人可以帮我让球在地上滚动吗?

swift realitykit visionos
1个回答
0
投票

angularVelocity.z实例属性以及相关设置可以实现这一点:

var angularVelocity: SIMD3<Float>
© www.soinside.com 2019 - 2024. All rights reserved.