Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Kartik1607 · Jun 28, 2015 at 04:04 PM · unity 52dcollisionphysics

2D platformer. Let player slide under object.

I am making a 2D platform.

There are 2 types of ground player can land on. One is normal on which a player can stand. The other one is like a rope. Player can hold it and just slide.

What would be best way to implement rope type of ground.

I have two ideas in mind

Idea 1) Create a collider under the actual rope sprite and add sliding animation. Player stands on the lower collider. Idea 2) Let rope have a collider. When player collides with rope, set gravity scale of player to 0. When collision exit, set gravity scale 1.

Any other method of producing result?

Also, currently I have added a collider under grounds which when triggers, it sets players collision to disable so player can pass through ground is he jumps up. And another collider just above ground, that re enables player collider. This sort of works like one directional collider.

Is there any easier implementation for this one directional collider.?

EDIT :

Sliding :

![alt text][1]

screen-shot-2015-06-29-at-23348-pm.png (19.6 kB)
screen-shot-2015-06-29-at-23348-pm.png (19.6 kB)
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SirBoboHobo · Jun 28, 2015 at 04:54 PM 0
Share

By slide, you mean to the side? you also said rope, so up or down? and is the sliding or climbing done automatically, manually (button click) or done step by step, like the player climbs a rope by holding up and if stopped he'll stop and continue only on button click again?

avatar image SirBoboHobo · Jun 29, 2015 at 07:01 PM 0
Share

Well, I don't know exactly your game, so things might not be right for you. I once did the same thing with just attaching a child with a collider and a rigidbody, above the player, slightly above the head, making the collider collider but making the player avoid the collision which will make him in the bottom. You can also add transform position. transform.position += new Vector3(2,-2,0) making it go 2 to right and 2 left.

avatar image Kartik1607 · Jun 30, 2015 at 04:27 AM 0
Share

Problem would be that once player collides, he would get pulled by gravity ins$$anonymous$$d sliding under rope.

avatar image SirBoboHobo · Jun 30, 2015 at 01:05 PM 0
Share

Why would he? if you've got a collider above him, then it should hold him. The collider should make the player resist the gravity. make sure it's a collider and not a trigger. and that the empty gameObject with the collider above the player attached to the player.

avatar image Kartik1607 · Jun 30, 2015 at 01:22 PM 0
Share

Seems that the only thing colliders do is "collide". When player hit's them, the player stops and is now pulled by gravity. I think I should just turn off gravity when player enters collider and turn it back on when he exits.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Immanuel-Scholz · Jun 30, 2015 at 08:22 PM

I would definetely go with Idea 1.

If you disable gravity and let the player "bounce" against the rope, you get strange results when the slope increase/decrease. Beside, why mess around with the physics world if you don't have to?

There is a third solution that fits well, if you have an explicit user-driven switch between rope sliding and normal walking (e.g. user needs to press a key): You actually have two collider on your player. One big normal collider that spans the whole body for movement and a second, very small circular collider where his hands are during the slide animation (in the upper-right corner of the normal character sprite area).

The rope itself has a collider that just spans the rope (it may go a bit below the rope, but not necessarily too much).

When you change to the slide state, disable the big and enable the small collider. If your character is positioned correctly, he will naturally "attach" to the rope since his hands are now on the other side of the rope. And he will naturally slide down the rope.

Be sure to assign correct layers to the rope collider to not have it collide with the main body collider or else the player may snap out of place when you switch back (and is generally unable to walk through a rope).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kartik1607 · Jul 01, 2015 at 06:30 AM 0
Share

Here is how I did this.

1) Created new gameobject and added sprite and a hook as child. 2) Hook position is just above sprite. alt text 3) Added rigidbody and script to player. 4) Added 2 colliders near rope and attached them as child to an empty gameobject. alt text One lower and one upper. Both are triggers alt text

When something collides with LowerCollider, it checks it is hook. If collided object is hook, then set hook collider to OnTrigger so that hook can go above the rope.

     void OnTriggerEnter2D(Collider2D collide){
         if (collide.name == "Hook") {
             collide.isTrigger = true;
         }
     }

When hook collides with upper collider, set OnTrigger to false.

     void OnTriggerEnter2D(Collider2D collide){
         if (collide.name == "Hook") {
             collide.isTrigger = false;
         }
     }

Now three things are happening

1) Player sprite have big collider, so it can't go above rope. 2) Hook collider is set to collide and not trigger. 3) Gravity is pulling player down.

So, hook will stick to top of rope. In game it would feel like player is hanging, but ins$$anonymous$$d, it is hook which is hanging.

screen-shot-2015-07-01-at-115218-am.png (11.7 kB)
screen-shot-2015-07-01-at-114854-am.png (16.2 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a solution to when colliders bypass? 2 Answers

Size and Position of BoxCollider 2 Answers

2D Mouse Look with Collisions 1 Answer

2d game end level with trigger and colission with trigger who to make a if condition 1 Answer

Smooth box to curve collision in 2D 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges