Post

Replies

Boosts

Views

Activity

Reply to GKAgent3d wander goal to stop agent from flying around
I am just documenting my discoveries in case it is of use to anyone else but I managed to perform a raycast from the node so that it detects things other than its child nodes, I run this function on update but I am not sure if there is a more efficient way of doing it. func heightTest(){         let result = sceneNode?.hitTestWithSegment(from: sceneNode!.position, to: SCNVector3(x: sceneNode!.position.x, y: -100, z: sceneNode!.position.z), options: [SCNHitTestOption.rootNode.rawValue: scene.rootNode])         if let intersection = result?.first?.simdWorldCoordinates {             print(intersection)         }     }
Topic: Graphics & Games SubTopic: General Tags:
Jul ’22
Reply to GKAgent3d wander goal to stop agent from flying around
I have semi sorted it by setting constraints to the Y value by using the following code in the RenderComponent of the entity;         let heightConstraint = SCNTransformConstraint.positionConstraint(inWorldSpace: false) { (node, position) in             var constrainedPosition = position             if position.y > 0 { constrainedPosition.y = 0; node.position.y = 0}             if position.y < 0 { constrainedPosition.y = 0; node.position.y = 0}             return constrainedPosition         }         node.constraints = [heightConstraint] I am wanting to have these agents move around on a landscape so they won't be on straight flat ground, my hope was to find a way of having the update routine for the node perform a raycast to check the height of the ground below it so it could move up and down and not be constrained to a static height but the node raycast only returns child objects of the node which the ground would not be so I have to come up with a new method if there is one.
Topic: Graphics & Games SubTopic: General Tags:
Jul ’22