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 awplays49 · Jul 01, 2015 at 03:39 PM · physicsstairs

Best way to make a physics engine allow player to walk up stairs?

I have a physics engine that I want to allow the player to walk up stairs. right now, I have a raycast that sort of checks in front if there's a step and enough room to walk up it, but it looks choppy since the player technically "teleports" up stairs, even with a delay it looks strange. How did starbound/terraria do it? I considered ramps but it just didn't work.

Comment
Add comment · Show 8
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 fuego_see_money · Jul 01, 2015 at 06:31 PM 0
Share

Is this for a 2-D game?

avatar image fuego_see_money · Jul 01, 2015 at 06:33 PM 0
Share

If so, one thing you could do is treat the stairs as if they are a ramp - meaning the collision would be a ramp, but the graphics are stairs.

That way, you can just follow the line of the ramp which is a little bit easier.

avatar image awplays49 · Jul 01, 2015 at 06:41 PM 0
Share

as said above, i tried that, but i didnt like it. is there another way to do it?

avatar image meat5000 ♦ · Jul 01, 2015 at 06:50 PM 0
Share

Do you even walk up stairs in Terraria?

You get to the edge and if its below a certain height your character just moves up and across 1 pixel.

You've just got to Lerp the movement, thats all.

avatar image awplays49 · Jul 01, 2015 at 06:55 PM 0
Share

$$anonymous$$aybe not terraria. I just assumed since starbound is very similar. But what do you mean?

Show more comments

1 Reply

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

Answer by fuego_see_money · Jul 01, 2015 at 09:14 PM

Try this: note that the stairGroundY and stairTopY float values might have to be gotten differently depending on how you have your stairs set up. (This example assumes that the bottom of the staircase is the transform.position.y, not the top)

 void OnTriggerStay2D(Collider2D c)
 {
     if(c.gameObject.tag == "Stairs")
     {
         Vector3 sPos = c.gameObject.transform.position;
         float stairGroundY = sPos.y;
         float stairTopY = sPos.y + c.bounds.size.y;
         Vector3 pPos = transform.position;
 
         float xPosRatio = (pPos.x - sPos.x) / c.bounds.size.x;
 
         float yValueOnStairs = Mathf.Lerp(stairGroundY, stairTopY, xPosRatio);
         transform.position = new Vector3(pPos.x, yValueOnStairs, pPos.z);
     }
 }

You can try that out - this is all from the top of my head so it may be flaky. Just comment if something doesnt work.

Comment
Add comment · Show 2 · 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 fuego_see_money · Jul 01, 2015 at 09:15 PM 0
Share

Also if anyone sees an error feel free to edit!

avatar image awplays49 · Jul 03, 2015 at 01:04 PM 0
Share

Thanks @fuego_see_money, and by the way you may want to check this question again http://answers.unity3d.com/questions/997372/child-object-consistency-issue.html

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

23 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 avatar image

Related Questions

Rigidbody character controller can't walk on stairs 0 Answers

2D 360 degress platformer example needed 0 Answers

Is there a rigidbody character controller 3rd person that can handel stairs (steps)? 1 Answer

Rigidbody Step Offset 3 Answers

Rigidbody climbing stairs 2 Answers


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