gpt4 book ai didi

SceneKit SCNPhysicsVehicle 问题

转载 作者:行者123 更新时间:2023-12-05 07:45:21 25 4
gpt4 key购买 nike

所以。我正在尝试在 SceneKit 中创建一个 SCNPhysicsVehicle。我遇到的问题是车辆底盘在我的场景中确实与地板发生碰撞,尽管车轮没有。车轮直接穿过地板,直到底盘与地板碰撞。我想知道我是否忘记了什么?我从未见过其他人为 SCNPhysicsVehicle 的车轮设置碰撞类别或类别位掩码。话虽这么说,我什至尝试过但没有运气!

非常感谢。

    let carScene = SCNScene(named: "art.scnassets/Textures/rc_car.dae") //rc_car.dae
let chassisNode = carScene!.rootNode.childNode(withName: "rccarBody", recursively: true)!
chassisNode.position = SCNVector3Make(0, 10, -30)

let body = SCNPhysicsBody.dynamic()
body.allowsResting = false
body.mass = 80
body.restitution = 0.1
body.friction = 0.5
body.rollingFriction = 0
chassisNode.physicsBody = body
scene.rootNode.addChildNode(chassisNode)


let wheelnode0 = chassisNode
.childNode(withName: "wheelLocator_FL", recursively: true)!
let wheelnode1 = chassisNode
.childNode(withName: "wheelLocator_FR", recursively: true)!
let wheelnode2 = chassisNode
.childNode(withName: "wheelLocator_RL", recursively: true)!
let wheelnode3 = chassisNode
.childNode(withName: "wheelLocator_RR", recursively: true)!


let wheel0 = SCNPhysicsVehicleWheel(node: wheelnode0)
let wheel1 = SCNPhysicsVehicleWheel(node: wheelnode1)
let wheel2 = SCNPhysicsVehicleWheel(node: wheelnode2)
let wheel3 = SCNPhysicsVehicleWheel(node: wheelnode3)

vehicle = SCNPhysicsVehicle(chassisBody: chassisNode.physicsBody!,
wheels: [wheel0, wheel1, wheel2, wheel3])



chassisNode.physicsBody?.collisionBitMask = USBitMaskManager.boundary | USBitMaskManager.sphere
chassisNode.physicsBody?.categoryBitMask = USBitMaskManager.sphere

// scene.physicsWorld.addBehavior(vehicle)

return vehicle

最佳答案

你查过github吗?有几个关于 Apples Vehicle Demo 的项目......例如一个在这里:https://github.com/ooper-shlab/SceneKitVehicle1.0-Swift

关于SceneKit SCNPhysicsVehicle 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41754017/

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