I want to check if there is an object below my player in my endless 3D runner, something like ray casting in unity. Is there a equivalent or does someone know how to do it differently maybe?
Checking for collision I tried but since it's a ball, making it have a dynamic physics body makes it go all over the place.
SCNNode exposes -hitTestWithSegmentFromPoint:toPoint:options:.
In the Fox: Building a SceneKit Game with the Xcode Scene Editor sample obstacles and the ground are static physics bodies and -[SCNPhysicsWorld rayTestWithSegmentFromPoint:toPoint:options:] is used to achieve what you're looking for.
Related
The gear joint in Box2d is great, but I don't know how to implement that in Sprite Kit. Is there any solutions to implement the gear joint in Sprite Kit?
Thanks.
Here are the available Sprite-Kit joints :https://developer.apple.com/reference/spritekit/skphysicsjoint
As far as I can understand, there does not appear to be a direct correlation to Box2D's gear joint, which seems to make one body rotate when another body is rotated.
In that case, you might want to investigate overriding the didSimulatePhysics or didFinishUpdate methods to manually set the rotation of one object based upon the rotation of another object:
https://developer.apple.com/reference/spritekit/skscene/1519965-didsimulatephysics
https://developer.apple.com/reference/spritekit/skscene/1520269-didfinishupdate
It might be as simple as:
wheel2.zRotation = wheel1.zRotation
but if the gears have different numbers of teeth (thus different ratios), you'll have to do some calculations.
In my game I would like that when a collision occurs, the designated sprite would undergo an "explosion" or "glass break" effect, in which the sprite is split up into random pieces which are then moved at a random rate, speed, and angle. I would imagine that something like this may require using particles or at the very a least texture atlas.
I found a little bit on this, but the questions/explantations were catered for Objective-C. I am fairly new to iOS development and have solely used swift, so I can't really translate from one language to another. Thanks.
I would suggest you to try using the SpriteKit Emitter class for this. Add a new SpriteKit Particle Effect file to the project and configure the type of explosion there. You do not need any code, to configure it as Apple has very conveniently provided an editor window for us to easily change the values.
Once you are satisfied with the way the emitter looks, you can then open the Game Scene (assuming that is where this collision would be detected) and type:
let explosionEmitterNode = SKEmitterNode(fileNamed:"the file name")
sprite.addChild(explosionEmitterNode)
Here sprite is the actual node to which you would like to add the emitter effect to. Or you could add it to the scene directly and set its position as:
let explosionEmitterNode = SKEmitterNode(fileNamed:"the file name")
explosionEmitterNode.position = CGPointMake(200,300)
addChild(explosionEmitterNode)
Is it possible to use Sprite kit's physicsBody to have element collision and still allow elements to go through each other? I'm interested in having the delegate to be called only when two borders hit each other and then allow them to go through each other afterwards :)
Yes this is possible. You can register for callbacks from collisions between objects but not have the collision affect the object itself.
The Ray Wenderlich - Sprite Kit book explains how to do this in the Zombie Conga game tutorial.
Try this one... http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
The section called "Collision Detection and Physics: Implementation" should explain what you need.
Just had a quick read and the two things you're after are...
contactTestBitMask this is which object collisions you want to receive collision callbacks for.
collisionBitMask this is which object will collide and "bounce" off each other.
In my game, I am using Cocos2D for the Game part. I am now trying to implement gravity but I am hearing that I have to use Box2D or Chipmunk. I could use those but is there any way to do this in Cocos2D, can anyone share any ideas/code just so I can add some simple gravity using Cocos2D if possible?
Thanks!
Its very easy using Box 2d and Chipmunk. Its inbuilt in cocos2d framework. Just when you start with the cocos2d application template(for iOS) select the Box2D/Chipmunk template. Its very easy.
Inorder to start with some gravity you have to create a world and add gravity vectors to it. You have a very simple and detailed tutorial in
http://www.raywenderlich.com/457/intro-to-box2d-with-cocos2d-tutorial-bouncing-balls
Its a tutorial that teaches you to create a bouncing ball app in Cocos2d Box2d Framework.
First create a CGPoint variable called gravity and set it's x value to 0 and it's y value to some negative number.
CGPoint *grav = ccp(0.0f,-9.8f);
Then, in your game loop, just use ccSub on each of your sprites positions.
sprite.position = ccSub(sprite.position,grav);
how can i perform animation on my moving object....
and how can i control collisions when some of objects are allowed to collide and some not...i,m beginner to corona and coding as well ...i look all the examples i know there r answers of my questions but i cant understand that properly...so any one help me??
In Corona when you create a Physics body you can specify the body type: static, kinematic, and dynamic.
Static bodies don't move, and don't interact with each other; examples of static objects would include the ground, or the walls of a pinball machine.
Dynamic bodies are affected by gravity and collisions with the other body types.
Kinematic objects are in-between Dynamic and Static bodies but doesn't response to gravity
For more information check these links: http://developer.anscamobile.com/content/game-edition-physics-bodies and http://developer.anscamobile.com/reference/index/physicsaddbody
By "animation" I'm going to assume you mean that the graphic changes. In that case you should use a Spritesheet:
http://developer.anscamobile.com/reference/sprite-sheets
As for collisions, there again I'll make an assumption because your question is a little vague. I interpret your question as wondering how to setup collisions where some objects don't collide with each other, and for that you want to set category and mask bits:
http://developer.anscamobile.com/content/game-edition-collision-detection#Collision_categories_masking_and_groups
It is very easy to make a animation by using corona sdk.If using sprite sheet animation u have use this link http://docs.coronalabs.com/api/library/display/newSprite.html.