Reputation: 2325
I have created a simple object an place it in SceneKit scene, on top of it I release another object that collide with the first object.All work fine..
But, when I scale my first node up the collision don't work anymore...
Any reason why?
Any suggestion how to fix this?
func loadStreet(){
let street = loadAssetWithName(nameFile: "street", nameNode: "street", type: "usdz", scale: SCNVector3(1,1,1))
street.position = SCNVector3(0, 0.5, 0)
street.eulerAngles = SCNVector3(0, deg2rad(220), 0)
let body = SCNPhysicsBody.static()
body.physicsShape = SCNPhysicsShape(node: street)
body.categoryBitMask = BodyType.floor.rawValue //2 int, assegnato solo a quel oggetto
body.collisionBitMask = BodyType.car.rawValue | BodyType.box.rawValue //1 con cosa puo collidere
body.allowsResting = false
body.restitution = 1
body.friction = 0.5
body.rollingFriction = 0
street.physicsBody = body
street.name = "street"
self.scene.rootNode.addChildNode(street)
}
Upvotes: 0
Views: 173
Reputation: 5015
You cannot scale existing physics bodies in SceneKit
. You will need to re-create them after each scale action (on the nodes). You must provide the scale factor from the node when you create it, otherwise the physics body will always be the original size of your geometry. (you can use the SCNVector3 directly if you want)
Consider you to use this kind of static body constructor:
let body = SCNPhysicsBody(type: .static,
shape: SCNPhysicsShape(geometry: shape,
options:
[SCNPhysicsShape.Option.type: SCNPhysicsShape.ShapeType.concavePolyhedron,
SCNPhysicsShape.Option.scale: SCNVector3(scale,scale,scale)]
))
PS: concavePolyhedron
is a shape type that follows almost exactly your custom geometry. It will be most precise, when i.Ex. working with dynamic bodies, that kind of fall/collide on that static body. (Keep in mind to apply the static physics body only AFTER you did scale and positioning operatons)
Upvotes: 1