ios - character is not moving in scenekit -
hey have imported character animation in xcode , want move touch in scenekit let suppose point point b . not moving have following code. don,t know why not working please help....thanks
//character imported blender var scene = scnscene(named: "art.scnassets/hero.dae")! // touches 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) }
your code attempting create , run new scnaction each time frame rendered. that's not want.
instead, create 1 scnaction when touch received, duration of, 10 seconds. run that. code belongs in touchesbegan()
(or maybe touchesended()
).
you can make code bit shorter using scnaction.moveby(_:duration:)
or scnaction.movebyx(_:y:z:duration:)
instead of moveto()
. you're calling movespeed
time interval, not speed, , terminology confusing future maintainers.
i don't see positioncamerawithhero()
ever called. should invoked renderer(didsimulatephysicsattime:)
.
note: in current implementation, renderer(didsimulatephysicsattime{)
never invoked. that's because have no animations running (see skscene becomes unresponsive while being idle). aware of apparent bug in playing
property being ignored on os x (see scenekit scnscenerendererdelegate - renderer function not called). however, once you've corrected creation of scnaction, won't have issue.
Comments
Post a Comment