Hey i have imported my character animation in xcode and i want to move it with touch in scenekit let suppose from point A to another point B . but it is not moving i have the following code. don,t know why it is not working please help....thanks
//character imported from blender
var scene = SCNScene(named: "art.scnassets/hero.dae")!
// touches for movement
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
var taps = event!.allTouches()
touchCount = taps?.count
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
touchCount = 0
}
func positionCameraWithHero() {
let hero = heroNode.presentationNode
var heroPosition = hero.position
let cameraDamping:Float = 0.3
var targetPosition = SCNVector3Make(heroPosition.x, 30.0, heroPosition.z + 20.0)
var cameraPosition = camera.position
var cameraXPos = cameraPosition.x * (1.0 - cameraDamping) + targetPosition.x *
cameraDamping
var cameraYPos = cameraPosition.y * (1.0 - cameraDamping) + targetPosition.y *
cameraDamping
var cameraZPos = cameraPosition.z * (1.0 - cameraDamping) + targetPosition.z *
cameraDamping
cameraPosition = SCNVector3(x: cameraXPos, y: cameraYPos, z: cameraZPos)
camera.position = cameraPosition
light.position = SCNVector3(x: heroPosition.x, y: 90, z: heroPosition.z +
40.0)
light.rotation = SCNVector4(x: 1, y: 0, z: 0, w: Float(-M_PI/2.8))
}
func renderer(aRenderer: SCNSceneRenderer, didSimulatePhysicsAtTime time: NSTimeInterval) {
let moveDistance = Float(10.0)
let moveSpeed = NSTimeInterval(1.0)
let currentX = heroNode.position.x
let currentY = heroNode.position.y
let currentZ = heroNode.position.z
if touchCount == 1{
let action = SCNAction.moveTo(SCNVector3Make(currentX, currentY, currentZ -
moveDistance), duration: moveSpeed);
heroNode.runAction(action)
}
else if touchCount == 2 {
let action = SCNAction.moveTo(SCNVector3Make(currentX, currentY, currentZ +
moveDistance), duration: moveSpeed)
heroNode.runAction(action)
}