Check for absence of contact - sprite-kit

I'm developing a puzzle platform game using Sprite Kit (and its physics engine). My player's physics body consists of a large hitbox covering most of the sprite, and a wheel with a pin joint anchored at the bottom of the hitbox. Rotation is added to the wheel to make the player move across the screen.
I need to know if the player is on the ground, or has fallen off a ledge; I know how to check for a physics body contact, but is it possible to check for an absence of contact (i.e. when the wheel leaves the ground)? I can't rely on comparing the Y position from the last frame as there are sloped surfaces that the player climbs.

You can use the didEndContact:(SKPhysicsContact *)contact to check if the wheel is no longer contacting the ground. Same principal as the didBeginContact:(SKPhysicsContact *)contact just in reverse.

Related

How to prevent sliding with rigid bodies in Unity?

So, I am using Unity's Rigid body physics engine. And I made the player using a capsule collider. And after creating another rigid body with a Box collider I tried to jump onto it, only, the player starts to ever so slightly slide on top of it until eventually sliding off.
I want to be able to make the player jump onto movable objects without sliding on top unless there is enough of a slope to make sense for the player to slide off of. Is this possible, or does Unity's physics engine prevent this?
This can be achieved by applying a Physic Material to the player's capsule collider. Specifically, take a look at the Dynamic Friction and the Static Friction of the Physic Material. You may also want to set the Friction Combine to Maximum, if you want to ensure your player has a good grip on the platform regardless of what kind they land on.
A higher Dynamic Friction will quickly stop your player object if it starts sliding, while a higher Static Friction will make it harder for the player object to start sliding if it is otherwise stationary.
There isn't an exact science behind choosing these values; you'll really have to play around with it to see what feels right for your game.

Climb down ladder in 2D platformer game

For my game, the player character requires to climb up and down ladders those are placed in the gameplay area.
At present, I can able to climb up for my player character to climb down at present I don't have anyway. Because platform box collider applied with platform effector, so for the climb up, effector does not create any problem but now after reaching the top, it becomes solid platform so now I can't able to move downside.
For climbing up, I have followed this tutorial: How To Make 2D Ladders In Unity - Easy Tutorial
I am looking to implement some physics so I can reach downside to the ladder after reaching top.
You need 2 boolean variables isClimbingUp and isClimbingDown which depend on pressed key and a second ray, which will check -Vector2.up direction. Then just add one more 'else if' statement for down direction.
Yes, I have managed to solve this, and the game is published in the stores.
You can check using the below link:
Humpty Trumpty's Border Wall
This is my overall physics setup for the stair:
I have applied a trigger collider to my stair object and disable player gravity scale when the player within the stair.
Then after within the trigger enter and exist, I have done this:
Physics2D.IgnoreCollision(m_CapsuleCollider, myStair.platformCollider, false);
Disable collision between player and platform colliders when the player is within the stair.
I don't think, Platform Effect 2D becomes useful to me in this process but I didn't remove this to remain in the safer side.
So you have to keep a reference of the platform object which is attached to Stair.
I hope you will get a general idea to solve this problem.

Unity 3d: Prevent Rigidbody from Falling Over

I have a 3d object (army man) that I added a RigidBody to. I have a Gun set up that shoots bullets at the army man --- when a bullet hits it, I want it to fall over. Now I have an issue where as soon as my game starts, my 3d object slowly falls over without any user interaction. I set X and Z freeze positions on the RigidBody but it still falls over. IF I set to freeze on Y position, my 3dObject will not fall over but then if I shoot the army man, it will just spin and not fall over. I attached a screenshot to show all my settings.
Your Collider's mesh is obviously standing on a point and is very unstable looking. Either give him a BoxCollider, or make a tall rectangle, attach a Collider to it and a RigidBody, and make the army man mesh a child of it. Remove all colliders and RigidBodies from the army man mesh.
In the rigid body you also have the option to freeze rotation around a certain axis:

How do I make my character's arms point towards the camera or cursor in Unity?

I'm making a fps game and I want my character's arms to rotate up and down depending where the cursor/camera is pointing at. The character already rotates when I turn left or right. Hopefully someone can answer my question. I'm new to Unity and I'm still learning how to code in C#.
For top and bottom rotation, create an animation for top aim, eye level aim and feet aim. send the value of your rotation to animator controller and animate according to it.

Cocos2d Chipmunk gravity and collision detection

I have a simple animation in Cocos2d Chipmunk with the tasks:
One round shaped sprite situated in the center of the screen, rigid body type. Center of gravity needs to be located in center of this sprite.
From different sides of screen (spontaneously and beyond screen size) other rigid round sprites must fall into central sprite to fill visible screen space.
Sprites should not overlap one another.
So the questions are:
How to reassign the vector of gravity to the center of the screen?
How to implement collision detection between rigid body types in Cocos2d Chipmunk?
Thanks, colleagues!
You can't set a center for the gravity. You can only set a direction (the same for all objects). It's possible to create an effect you describe, but you'll have to do the work yourself. In every frame you have to set a force or apply an impulse on every body in the direction of your gravity. And the "regular" chipmunk gravity should be (0, 0).
See this tutorial about collision detection.