Game Development Reference
In-Depth Information
// Reduce this vector to be the same length as
our movement speed
offset = GLKVector2Normalize(offset);
offset = GLKVector2MultiplyScalar(offset, 10);
[self.physicsBody applyForce:CGVectorMake(offset.x,
offset.y)];
}
4. Now, add the following code in the update function:
if (self.behaviourType == Seek) {
[self seek:self.target deltaTime:deltaTime];
}
This function will be executed if the player behavior is set as seek.
5. Now we are all set to test the function we have written in the previous few steps.
So, open the GameScene.m file and create the instance of the newPlayer ob-
ject at the top of the implementation file. The implementation code should look
like the following:
@implementation GameScene {
float lastTime;
Player * newplayer;
SteeringBehaviorType behaviourType;
}
6. Also, add the following line of code in the init method we have written earlier:
self.physicsWorld.gravity = CGVectorMake(0, 0);
newplayer = [self createPlayer];
newplayer.position = CGPointMake(size.width/2,
size.height/2);
behaviourType = Seek;
newplayer.behaviourType = behaviourType;
if (behaviourType == Seek) {
newplayer.physicsBody = [SKPhysicsBody
Search WWH ::




Custom Search