unity2d create a one side collider - c#

I have a maplestory game demo
I need character can jump through a collider from one side
the collider in my character and ground are like this:
character:capsulecollider2d
ground:polygoncollider2d
so the character can stand on the ground
also can jump on the ground
but now I want character jump from bottom of the ground,it cannot work
so, How can I deal this problem? Is there a configuration that can make collider only have one side?
-------------------------------------2017 08 11-------------------------------------
thanks a lot every one
thank you #EmreE #Jeroen De Clercq
I resolved this problem by using Platform Effector 2D provided by #EmreE
first: add platform effector 2d on my ground
and select "use one way"
second:select "Used by Effector"
now it works :)

Put your floor in a layer;
put your platforms in a layer;
When you jump remove collision with platform layer until u have reached a direction that points towards the floor.
When you press down key remove collision with platforms until you have passed one platform layer.
More information here ; https://docs.unity3d.com/ScriptReference/Physics.IgnoreLayerCollision.html

Related

How to prevent colliders from stopping each other while colliding

I am working on a 3D unity project, which I have a platform in it and a character who runs on that platform, I placed the character on the platform but it started to fall down so I solved the problems by following these steps:
added a capsule collider to the object, it still fall through the platform
added a collider to the platform, then it didn't fall down but now these two objects are soled to each other so the character is just moving her legs in the same place,
Is there any way to make the character move on the platform while still using colliders?
Note 1: I made the collider trigger in the image to make the same exact behaviour with out colliders.
Note 2: I tried to put each one of them on a different layer but I get the same problem.
code:
void Update ()
{
rbody.velocity = new Vector3(rbody.velocity.x,0f,playerVelocity*Time.deltaTime);
rbody.transform.rotation = Quaternion.identity;
.
.
.
}
Making the collider trigger is like adding no collider. Trigger is only used when you want the collider to detect something but not stop it from running into things. So I believe you should add a non-trigger collider to both the character and the platform but make sure that the colliders are not intersecting when you put the character manually at first. If that didn't work, tell me exactly the coordinates of the character and the platform and the sizes of their colliders and I will try to replicate your scene to figure out the problem. Hope this helps!
Hi Friend you have 2 options...
Change the mass of your RigidBody
Use PhysicsMaterial and reduce the friction between the objects (Add a Physic Material to your Platform)
Increase the force and movement speed in your script.

Unity breakout game change direction of ball based on which part of the paddle it made with collision using c#

I am experimenting with a 2D breakout game (in c#) using Unity 5 and wanted to know how I can change the direction of the ball based on which part of the paddle it made collision with.
For example if the ball touched the left part of the paddle then the ball should go left and if it struck the middle then it should go straight up and if it struck the right side then go right.
You can make 4 different box colliders 2d on the every side of a paddle as a child object and add OnCollisionEnter2d() method to them where you can apply your mechanics

How to add physics to an object in Unity 5

I'm having a problem with Physics! I have imported an object which a bridge from 3ds max to unity 5 ,but the problem is that whenever I want to walk through on it ,I just fall down. It's like there's nothing called BRIDGE! I know there must be a problem about Physics. But how to fix it ?!
When importing a model into Unity it does not have any Collider.
Even though using auto-generated "MeshColliders" is an option
I highly recommend not to use them.
You never need such highly detailed colliders in a game.
Instead, you have to
Add the colliders manually
Here is a little step by step guide
This is the imported model (made with blender) without any collider whatsoever
First thing to do is add a new box collider to the components
as shown in this gif
The next thing to do is scaling the box collider
by either entering the values manually or using the drag/GUI version like I do in the gif below
(you probably know that already but the mode can be changed to orthographic by licking the small cube in between the cones in the upper right)
If necessary you can add as many "detail" collider as you want
by repeating the steps. Sometimes sphere or capsule colliders might fit better but keep in mind that they have a higher resolution!
In this case i added another box collider representing the upper part of the car:
Thats all you need to make things collide with your object
Right now you only have a MeshFilter, MeshRenderer, and Animator component attached. You walk through it because the mesh is only being rendered. In order to add collision, add a MeshCollider component to it.
Joe offers another way to do it with box colliders. There is a bit to know about both methods:
Box colliders will take more time to set up (rather than just adding a
component) and will have less precision. They will have faster performance.
Mesh colliders do not collide well with other mesh colliders.
However, this is often not an issue. If a mesh collider has the
"convex" checkbox checked then it will collide just fine with other
mesh colliders. Small items and any convex-shaped meshes should have
"convex" checked.
For something like your bridge.. it depends on your game. If you are doing a top-down game with limited mobility (no jumping) then box colliders may work for you. If you are making a first-person game then I would strongly suggest mesh colliders. If you decide to use box colliders then you must set them up carefully. Otherwise, physics may not match up with what the player sees!
Do not worry about performance at this time. Worry about it later IF it becomes an issue. With the physics upgrade in Unity 5, it probably won't be.

Somethings wrong with my colliders (Unity Game Engine)

I have a character, that has a character controller attached to it I am using transform.position, transform.forward and transform.rotate to move with the 'wasd' keys, that all works fine.
However it will not collide with any sort of colliders, whether is be box colliders or mesh colliders. trigger works on my character, i.e. it can trigger an object to destroy if it passes through, but the colliders that are not set to triggers (like walls), don't block the player, the player just goes through them.
Any ideas?
Note: using C#, unity free version 4.5.1
You Should not use transform for colliding.
Add ridged body and get reference to ridgedbody.
Then use reference.addForce
Guys i figured out the problem, as the previous answer said i should not use transform with character controller, however there's no need to change any colliders, i still kept my character controller on my player, but rather i used controller.SimpleMove to move the character, that fixes the problem and i get to keep the character controller on my object (no need to add extra colliders or rigidbody to the player).
http://docs.unity3d.com/ScriptReference/CharacterController.SimpleMove.html

Unity - 2D Moving platforms parenting

I am struggling with a character parenting on moving platforms in 2D game.
I’m using OnTriggerEnter2D() for a detection when player steps on the moving platform. It changes his parent to that platform.
With common moving platforms (left-right) everything works fine, if a character stands on that platform he moves parallel with it, he can walk, jump etc.
The problem appears when I use the platform that hangs on two ropes connected with HingeJoint2Ds.
The player should swing that platform by walking left and right.
When using a keyboard input everything works fine but with a touch-input controller, when player doesn't move, the character remains on one place and doesn’t move with that platform. In a hierarchy panel is everything correct, player is a child of platform and the platform is moving but character isn't.
For moving character I’m using this: (part of character controller)
float move = Input.GetAxis ("Horizontal”);
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
That’s the same for keyboard and touch input. Difference is only in the “move” variable getting.
The solution for moving and swinging platforms is same too. (hierarchy, parents, colliders etc.)
I am struggling with this for several hours but I have no idea what could be wrong.
Thanks for any help.
What do you call a "touch input controller", is it a touch device? If so, are you sure Input.GetAxis("Horizontal”) does anything on touch devices? won't it just return 0 always?
Have you tried logging your move value, or copying it to a public variable to watch it evolve in the inspector? Maybe the values are orders of magnitude apart between one controller and the other, in which case you would need a multiplier.

Categories