Climb down ladder in 2D platformer game - unity3d

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.

Related

Unity Tilemap 2D player getting stuck in a platform

the question is quite simple. I have this platform and I do not want the player to collide with it when it jumps on the side or under it. In my Tilemap I have already added a composite collider 2D to the collider, so it doesn't separate each tile into a different collider.
As you can see, there are 2 tilesets but 1 collider thanks to the composite collider 2D. I have also changed the physics of this tileset, which is why the collider is so small (which is intended) so that the player can walk under it with no issues: Ej
However, when I jump to try to reach it by side, it does collide, ignoring the side arc function. I have never used a side arc, so I'm not sure if it should be done like this.
This is what happens instead of going through the platform it collides with it ... I thought Side Arc would let me go through the platform if I go by the sides, which is what the logic of the statement of a side arc would do but I guess I was wrong.
it gets stuck instead of going through, so what am I missing or doing wrong ?
I know I could simply hardcode it by making it trigger and when the "ground" collider attached to my pj touch it remove the trigger but I wanted to know if it was possible without that.

How can I remove small part of collider of game object in unity 2d

click here for gif show of what I want
I want to remove mesh of object when user click on object and also remove its collider to make another object fall from that removed mesh area...
I am using unity since last month so I don't have much experience and knowledge, please help me...
Creating the destructable ground particles
One way to achieve whats shown in the gif is by creating a prefab of e.g. a circle collider that is instantiated in the area of where the dirt is in your gif. It acts as a "ground particle" and keeps the objects above itself.
You instantiate a lot of them in the area so it acts as a big collider although it is actually a whole array of smaller colliders.
Implementing the interaction logic and deactivating the ground particles
Ater that you implement the functionality of dragging the mouse over the ground particles, removing them. That is also not difficult. Shoot raycasts into the screen at the postition of the mouse (remember to use Camera.ScreenToWorldPoint) and get the collision information (confer to https://docs.unity3d.com/ScriptReference/Collider2D.Raycast.html). With the collision information you can get the reference to the instance of your ground particle(raycasthit.other.gameobject) which is then disabled through script(gameobject.setActive(false)).

Unity - How to give some flexibility to colliders

Hi I'am new to Unity and I was trying to implement a game using tetris blocks.
The game's goal is to build the highest tower before it collapses. However there is a problem in my implementation which is seen in the picture below.
I achieve the building a tower task by activating the rigidbody gravityscale when it collides with something. With that way it can collapse after touching somewhere not before. But I want to have the flexibility of some collisions. In the situation seen in the picture below, that 'T' block will collide with the point in the red circle before landing safely and gravityscale of the rigidbody will be set. So it will drop but I don't want it to happen becasue the collision area is too small. I want to make it land safely with some flexibility.
I tried to make colliders' size 0.9 but that just disrupts the scale of the world.
Can I do something like this :
If collision happens, check collision area and if the area is lower than lets say 0.1, do not trigger rigidbody gravityscale.
what about using capsulle collider 2D with small radius?

Unity OnTriggerEnter triggering wrong

I have a game in which I want my player to jump from one platform to the other. On my platform I have a box collider.
When I tried to jump, sometimes my player would hit the side of the collider and start grinding up against it and would slip down and finally trigger the death condition. To prevent this, I put a trigger collider next to my platform. I also put the trigger collider slightly below the box collider so that in case my player jumps on the edge, he doesn't activate both.
If the trigger activates, I play the death function, otherwise I assume the player has made a solid jump and go on with the other game logic.
However, I notice that sometimes when the player lands on the edge of the platform it enters the on collision function as well as the on trigger event.
This is strange because I notice in my scene view that the player collider has not entered the trigger collider below the platform.
I have tried adding raycast to the mix but I'm still getting this bug, and even despite the raycasts I don't understand why OnTriggerEnter is triggering when the player hasn't entered the trigger.
I did consider the fact that the player collider might push into the platform collider since the player is falling with some speed but I thought it would show up in the scene view.
My question is, when I land on the platform collider how is it possible for the trigger collider to trigger? I'm jumping on top of it, not from below it. If I miss the platform completely the trigger fires as expected but on occasions it will land on top of the platform have no overlap with the trigger collider and still fire it.
/e
this is a side on view of my 3d environment. It is not the exact depiction but to simplify it for you guys. My player is jumping from one platform to the other, both of these platforms are for all means and purposes 3d cubes with box colliders. In between the two platforms but at a slightly lower level I have a trigger collider.
when my player hits the trigger collider its game over. my question is sometimes my player will land on the edge of the box collider as in the sketch but for some reason it will trigger the gameover trigger collider when there is no penetration of my player collider with the trigger collider, as you can see there is plenty of space in between them they arent even touching.
To sum up - my ontriggerenter is running when there is no visible contact between my player and the trigger collider, question is why?
ignore the draw ray, as you can see, my player collider is firmly on top of the platform box collider, and yet ontriggerenter for the collider next to and below the platform is triggered and my player goes into death animation. I cant be more specific then this, its up to you guys to help me out now and explain why this is happening. my player is far away from the triggercollider they arent touching.
As always, no response from Stackoverflow.
Anyways I was able to find a solution to my problem. The solution was ugly and its not worth sharing but for anyone else stuck with collision detection and such the following things or a combination of the following might help you find a solution.
1 - You can consider changing the rigidbodies colliding between each other to continuous or continuous dynamic. This will increase performance overhead but will lead to much better collision between the rigidbodies.
2 - In settings, physics manager you can try to turn up the Default Solver Iterations. From the documentation: Solvers are small physics engine tasks which determine a number of physics interactions, such as the movements of joints or managing contact between overlapping Rigidbody components. Use Default Solver Iterations to define how many solver processes Unity runs on every physics frame. This affects the quality of the solver output and it’s advisable to change the property in case non-default Time.fixedDeltaTime is used, or the configuration is extra demanding. Typically, it’s used to reduce the jitter resulting from joints or contacts.
These or a combination of these might be something to look at.

How to restrict which colliders are triggered?

Sorry if similar questions have already been asked.
I have a character that can hold up a shield to block incoming damage. The character has a circle collider for his body space. The shield has a box collider that blocks off a portion of whatever direction he's facing, and it's only enabled when the player is holding down a button. My enemies have weapons surrounded by triggered box colliders which are enabled when they decide to attack.
So, my problem is that when my character is attacked while shielding, sometimes his body collider is detected and sometimes his shield collider is detected. I can't find any consistency no matter what I try.
[Screenshots] (http://i.imgur.com/VHujbcG.png)
[Code] https://gist.github.com/siketh/2401454977d10ed7699b
I've been struggling with this all day and need another set of eyes. This isn't a serious project so if you need to see anything else I'm happy to post more code or explain more of my design.
It's probably because the weapon intersects with both the character and the shield at the same time. There are great tools in Unity if you want to see if that's the case.
Notice that Unity has "Play", "Pause" and "Play one step" buttons at top of the editor window. You can pause the game with Debug.Break(); instantly at the moment player fires or swings the weapon. Then you can watch what's happening step by step. Select the character, the shield and the weapon so that you can see their colliders in action. This way you can see what collides with what exactly step by step.
Similarly you can see the action in slow motion by adjusting time scale. Something like Time.timeScale = 0.1f;
To prevent this,
You may want to look at continuous collision though I've always failed to use it properly in Unity.
You may want to utilize more physics layers. http://docs.unity3d.com/Manual/LayerBasedCollision.html
You may want to detect collisions by using raycasts.
You can enlarge the shield and reduce the weapon swing speed or bullet speed. So that it's impossible to penetrate through shield.
You can decrease the period of FixedUpdate calculations so weapon movement will be smoother and there will be less penetrations.
http://docs.unity3d.com/Manual/class-TimeManager.html
There is a high probability that you are detecting both weapon-to-shield and weapon-to-player collision in one step. So why not postpone the decision one FixedUpdate later. So that you can check if there was only weapon-to-player collision or both collisions. If weapon-to-shield collision detected in previous update, then you know player hit the shield no matter if weapon passed through the shield or not.
Let's say there is no way you can detect if weapon hits the shield or the player. By using some simple geometry, you can check if the attack is coming from the direction of the shield or not.
Good luck :)