Causing transitions when sprites collide in cocos2d - iphone

I was wondering when I use CGRectIntersectsRect and two object collide, where in my update method should I put the transition if it's possible? I want to use this for when my character collides with an enemy, a game over menu appears.

The best place is in your main game loop (Probably is the scene that run your game).
If you are checking the collision in this main game loop, just call a function to itself. If you are checking the collision in a method of the sprite that are colliding, then post a NSNotification or use the delegate approach.

Related

In Unity 2D, how do I achieve Non-trigger collsion that doesn't "physically" move the rigidbodies?

I have a bullet game object and an enemy game object.
I want to have the ability of getting the collision point/contact, which's why I think I need the collider of the bullet to not be a trigger collider - this way, I want to have the bullet bounce off the enemy. At times, the bullet will need to bounce off of rectangular objects (not a problem), but I also want the bullet to bounce off of elliptic objects (the problem).
I want the bullet not to "physically" push the enemy, which is why, intuitively, I should set the bullet's collider to be a trigger collider.
When the bullet's collider is a trigger collider, I seemingly don't have a way to implement the bouncing.
But when the collider's not a trigger collider, it pushes the enemy object.
There's no code errors, but I think the code hasn't got anything to do with the problem.
I suspect the problem may have something to do with the Physics Collision Matrix.
EDIT
It seems that raycasting would be the solution to the problem, as Leoverload proposed. My problem became a different problem now, so I'll close off this thread, and open a new one.
Thanks for the help, #Leoverload ! :D
For the position of the hit it's very easy. You must have 2 colliders and 2 Rigidbody and then you can simply add a
Void OnTriggerEnter2D(Collision Coll) and inside it check for the tag : if(coll.compareTag("surface")) and inside you can get the position with collision.transform.position.
The collision matrix on the Physics menu only allows to remove Collision between certain layers, it's useful if you want the enemies not to push eachother!
If you don't want the player pushed you can change the collider to trigger, and destroy the bullet just after the collision with the same method as before with a void OnTriggerEnter2D and the compareTag. In this way it will look like it touches the enemy and explode, but it won't actually touch anything. If you want to add knockback to the player then you could do a simple AddForce based on the direction of the bullet and the work is done!
If you want to avoid the bullet to move walls you can set walls to static and it should work fine

Unity Particle System - Absorb Particle From a Destroyed Game Object to Player

I want to make a particle effect in my game when my player hit (OnTriggerEnter2D) a game object, that object explode and make a few particle and after a few seconds those particles absorb by player.
Instantiate GameObjects(particules) when your object is destroyed.
In particules put a script
In Start() method use a Coroutine and set your number of seconds (https://docs.unity3d.com/ScriptReference/WaitForSeconds.html)
In your coroutine method make this object look the player and add a mouvement
When the particule hit the player dertroy it
I hope that will help you.

Trouble With Colliders

I am currently making a 2D game and I am trying to make my character die whenever his head touches an object, however, he will be walking on the same kind of objects. How do I differentiate when his feet touch something as compared to when his head touches something? Would I use two separate box colliders? If so, how would I code that?
Instead of using colliders to detect when the player's head touches the ceiling, I would use one collider for the whole body. Then, use Physics.Checkbox to determine whether anything is colliding with the player's head. For the calculation, you can specify a layer to omit, and naturally one would omit the player's collider.
So, your code might look something like this:
if(Physics.Checkbox(center, extents, rotation, playerLayerNumber)) {
//Handle player death here...
}
The only problem being, of course, that your player will die when anything touches their head, if you've got other objects in your scene. Hope I could help!

Directional Collision Detection in Swift

I am aware of how to use the SpriteKit physics engine to detect when a collision occurs between two nodes, however, I'd like to be able to detect this and also get the direction relative to one of the objects that the collision occurred. Incase anyone is curious, I'm asking this so I can make a platform game and I need to detect when something is resting on the top of the floor. Any help is appreciated, thanks!
Implement the SKPhysicsContactDelegate on one of your objects (perhaps your scene object). Set your scene's physicsWorld.contactDelegate to the object.
In the contact delegate's didBeginContact(_:) method, you are given an SKPhysicsContact object. The contact's contactNormal property should be the direction you're interested in.

Unity 2D: How would I go about making a block that shoots when the player touches it?

I am making a 2D platformer in Unity and I want to make a block that works very similarly to the shooting blocks from Kid Chameleon. When they are touched by the player, they shoot from what every direction the mark is on and the bullet can hurt the player and enemies, destroy crates and activate other shooting blocks. Can some one tell me how I can achieve this because I have no idea where to start?
For start you can use OnMouseDown() event for detecting a click(or touch) on an object and then you can Instantiate a bullet object from block and give it's rigidbody a velocity to move towards that. and you can use OnCollisionEnter2D(Collision2D c) event for every Gameobject that you want to detect collision and do your job.