简体   繁体   中英

ARKit - SCNNode continuous movement

I'm trying to create an application in which the user stacks different geometric shapes. In a .scn file, which is loaded inside the ARSCNView, I insert a static plane and then at each tap of the user, the app inserts a dynamic SCNNode.

The first node is being inserted a few inches above the plane, to replicate a falling object. And then, each other node is being dropped on top of another.

This is the main idea of the application; the problem appears after adding 3 or 4 nodes, they appear to slide of each other, almost jiggle, and the whole structure collapses.

This is my node I'm inserting:

let dimension: CGFloat = 0.075
let cube = SCNBox(width: dimension, height: dimension, length: dimension, chamferRadius: 0.0)
let node = SCNNode(geometry: cube)

node.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.dynamic, shape: nil)
node.physicsBody?.mass = 2.0

node.physicsBody?.friction = 1.0
node.physicsBody?.restitution = 0.01

node.physicsBody?.damping = 0.0
node.physicsBody?.angularDamping = 0.0

node.physicsBody?.rollingFriction = 1.0

node.physicsBody?.allowsResting = true

let insertionYOffset = 0.3
node.position = SCNVector3(hitResult.worldCoordinates.x, hitResult.worldCoordinates.y + Float(insertionYOffset), hitResult.worldCoordinates.z)

I've tried to play with the values and these are the best ones, but they aren't enough to create a stable structure of blocks.

As a requirement, I need to keep the blocks dynamic, they need to be affected by gravity, wind, etc.

这个问题最有可能与一个名为Dynamic的因素有关,它允许它连续移动或者可能与对象相互碰撞来解决这个问题所需要做的就是将碰撞掩码改为两个不同的数字。

I see two points that may be the flaws of your simulation:

  • Your objects are stacked. When two objects collides there's a small amount of error added in order to keep the physics in a stable phase and prevent weird behaviors. So when you stack objects you add error amounts and the simulation becomes inaccurate. I suggest making objects static over time or depending of the position, or reduce gravity by a bit.
  • Most of the physics engines works better with objects sized with the unit size (most of the cases, it's 1 like in Box2D or PhysX). Objects that are very small or very big tend to act less natural. 0.075 sounds a bit small for a simulation. I don't see a obvious solution, maybe look for a way to change the reference size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM