Detect collision with enemies head with cocos2d - iphone

I want to detect a jump on an enemies head (like in super mario). How can I do this?
If you didn't understand what I mean just say something :)
I dont need to use cocos2d but it would be better with that :)

I'm not familiar with cocos2d so I can't help with specifics but:
If you can determine the player collided with an NPC, just check if the bottom of the player is what collided with the top of the NPC. If it did, he must have landed on his head.
To be extra sure, you could also check if the player's velocity states that he's moving down but that's probably not necessary.

Related

Is there a way to have camera follow g-force in Unity 3D (versioon 2019.3.15f1)?

I am making a game where at one point the player flies a plane/spaceship, and was wondering if there is a way for the camera to move slightly up when the player flies down, and vice versa, same for left and right so that it might make it feel better to play, and slightly more realistic then just a static camera movement.
Thanks a lot !
PS: Beginner here, so sorry if it's an obvious answer...
You can use Unity Standard Assets script CameraFollowsPlayer (Not sure of the name but it is something like this) and you drag and drop your character to your new Camera. It should do the trick with the delay movements. Alternatively you could use Lerp and transform Cameras Position in LateUpdate() method.

Spritekit physics failing to detect second adjacent item

Kinda what the title says, I have a "wall" made out of multiple segments specifically for modular purposes. I have a contactTestBitmask that forces the player to stop moving in the direction of the wall once collided, but, if you slide along the wall to another segment, the player just rolls straight through it. I cannot do a collisionBitmask as the player runs fast enough to "phase" through the walls. I also cannot do collision as my camera and lighting are also dependent on the player's movement and position, and will not interfere with the walls (I think). If anyone could help point me in the right direction to allow me to make solid modular walls, I'd greatly appreciate it.
Figured out the source of my problem, contact IS happening, I just have wonky flags and the system doesn't like that. I need a contact currently happening method, I guess

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!

swift usesPreciseCollisionDetection does not work?

i have made an app where you need to shoot on an enemy but sometimes the bullet goes through the enemy. swift sprite kit game when I shoot on a enemy sometimes the bullet goes trough the enemy, how can I fix this?
so i added usesPreciseCollisionDetection = true.
but the bullet sometimes still goes trough the enemy. so my question was did i do something wrong or is usesPreciseCollisionDetection not working?
thank you for reading my question I hope someone can help me.
You are using moveTo to move your bullets, Physics Engine does not work with moveTo the way you want it to, usesPreciseCollisionDetection will not do anything
As far as your Physics World is concerned, your bullet is stationary. You are just playing God and performing some kind of molecular transportation to move items.
You need to use functions like applyImpulse or even just give the physicsBody a velocity if you want this to work correctly
I had similar problem that is collision was sometimes not detected even when usesPreciseCollisionDetection was set to true and both SKPhysicsBody were rectangles. In my case usesPreciseCollisionDetection for some reason started working much better when I changed one of the SKPhysicsBody to circle instead of rectangle. Try changing your bullet physics body to circle, it seems that collision detection algorithm with circles is more precise so that might help you.

Boolean question in Cocos2d

I am making a game in Cocos2d. I have enemies in the game. I want them to shoot at the character. Currently, I have a boolean that says
buffDude.shoot = YES
when it is done moving. And in the Enemy class, I want it to detect if the boolean is YES or NO, and shoot if it is YES. And, while we're on that note, if I declare
buffDude.shoot = YES
in the
+(id)enemy
method, it will create a bullet at the bottom of the enemy sprite, but the bullet will not move. I know that it is because it didn't add the bullet to the Layer, it added it to the Enemy, but I don't know how to add it to the layer. Please Help! This is really driving me crazy, and help would be appreciated.
EDIT:
Okay, to get it to work, I just created a different layer and added the enemies and their bullets to that. Thanks for the help!
I am not really sure what you are trying to do. But I can only assume that you are adding a bullet sprite. And if you are adding a bullet sprite in you Enemy Class like: [self addChild:bulletSprite];, the Enemy class will own that bullet. Instead, if you would like the bullet to be visible in your game scene, you can add the same code in HelloWorldLayer.m instead.
But as I said, I'm not really sure what your problem is.