objective c - Wall collisions in scene kit -


i'm trying write game node can move contained series of walls- maze game. basic thing going pulled apart apple's scenekitvehicle project (https://developer.apple.com/library/ios/samplecode/scenekitvehicle) basic elements , put in cube (the box node in code below) instead of physics vehicle in original code.

problem is, programmatically move box node until reaches wall , continues straight through wall without stopping. meanwhile, can put vehicle code in , stop when reaches wall.

- (void)setupenvironment:(scnscene *)scene {     //floor     scnnode*floor = [scnnode node];     floor.geometry = [scnfloor floor];     floor.geometry.firstmaterial.diffuse.contents = @"wood.png";      scnphysicsbody *staticbody = [scnphysicsbody staticbody];     floor.physicsbody = staticbody;     [[scene rootnode] addchildnode:floor]; }  - (void)movebox {     scnaction *movebyaction = [scnaction movebyx:0 y:0 z:-3 duration:0.1];     scnaction *repeataction = [scnaction repeatactionforever:movebyaction];     [_boxnode runaction:repeataction]; }  - (void)setupsceneelements:(scnscene *)scene {     // add walls     scnnode *wall = [scnnode nodewithgeometry:[scnbox boxwithwidth:400 height:100 length:4 chamferradius:0]];     wall.geometry.firstmaterial.diffuse.contents = @"wall.jpg";     wall.geometry.firstmaterial.diffuse.contentstransform = scnmatrix4mult(scnmatrix4makescale(24, 2, 1), scnmatrix4maketranslation(0, 1, 0));     wall.geometry.firstmaterial.diffuse.wraps = scnwrapmoderepeat;     wall.geometry.firstmaterial.diffuse.wrapt = scnwrapmodemirror;     wall.geometry.firstmaterial.doublesided = no;     wall.castsshadow = no;     wall.geometry.firstmaterial.locksambientwithdiffuse = yes;      wall.position = scnvector3make(0, 50, -92);     wall.physicsbody = [scnphysicsbody staticbody];     [scene.rootnode addchildnode:wall]; }  - (scnnode *)setupbox:(scnscene *)scene {     scnbox *boxgeo = [[scnbox alloc] init];     boxgeo.height = 5;     boxgeo.width = 5;     boxgeo.length = 5;      scnnode *box = [scnnode nodewithgeometry:boxgeo];     box.position = scnvector3make(0, 0, -30);     boxposition = box.position;     box.rotation = scnvector4make(0, 1, 0, m_pi);      box.physicsbody = [scnphysicsbody kinematicbody];      [scene.rootnode addchildnode:box];      return box; }  - (scnscene *)setupscene {     // create new scene     scnscene *scene = [scnscene scene];      //global environment     [self setupenvironment:scene];      //add elements     [self setupsceneelements:scene];      //setup box     _boxnode = [self setupbox:scene];      [self movebox];      //create main camera     _cameranode = [[scnnode alloc] init];     _cameranode.camera = [scncamera camera];     _cameranode.camera.zfar = 500;     _cameranode.position = scnvector3make(0, 60, 50);     _cameranode.rotation  = scnvector4make(1, 0, 0, -m_pi_4*0.75);     [scene.rootnode addchildnode:_cameranode];      return scene; }  - (void)viewdidload {     [super viewdidload];      [[uiapplication sharedapplication] setstatusbarhidden:yes];      scnview *scnview = (scnview *) self.view;     scnview.backgroundcolor = [skcolor blackcolor];      scnscene *scene = [self setupscene];     scnview.scene = scene;     scnview.scene.physicsworld.speed = 4.0;     scnview.pointofview = _cameranode;     scnview.delegate = self;      [super viewdidload]; } 

any ideas why box node doesn't stopped wall?

might problem box node needs propelled force vehicle in order wall stop it?

what trying accomplish little tricky. moving box , making react physics interaction not possible in way envision kinematicbody.

you can keep that, need fake collision based on position/bounding boxes, or listen intersections in physics world.

you change dynamic body, interacts other dynamics objects. however, in movebox function, using scnactions move box. if using dynamicbody, cannot moved way. you'll have use forces.

the last option use scnconstraint. not prettiest, if wall doesn't move trick.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -