Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by andrew_196 · Mar 19, 2016 at 06:25 PM · 2dunity 2dgravity

2D Keeping player stuck to a square platform

Hi,

Just looking for advice and to be pointed in the right direction. Don't feel obliged to write and code really suggestions could work too, thanks.

But the issue I'm having is making my character walk around a cube as if it was stuck to it, like walking round a corner of the cube. (described in the screenshots attached)

The way I'm achieving this now is just by adding a:

 rb.AddForceAtPosition (-10f * transform.up, transform.position);

This doesnt work completely really since if you walk of the edge to quickly it will just send you of the screen. If you can recommend a better way to do this that would be amazing.

Thanks in advance!!

alt text alt text

screen-shot-2016-03-19-at-181659.png (341.8 kB)
screen-shot-2016-03-19-at-181644.png (339.6 kB)
Comment
Add comment · Show 1
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 andrew_196 · Mar 21, 2016 at 12:23 PM 0
Share

anyone have any ideas

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ali-hatem · Mar 19, 2016 at 06:51 PM

  1. disable gravity

  2. add 4 empty game objects with colliders @ the 4 corners of the square

  3. use OnCollisionEnter2D to detect there names or tags to send them to the desired direction example :

    void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Down") rb.velocity = new Vector2(0, -5); }

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 andrew_196 · Mar 19, 2016 at 07:47 PM 0
Share

Would this send you off the screen when you hit the edge? since you wouldn't have fully crossed/went over the corner.

avatar image Ali-hatem andrew_196 · Mar 21, 2016 at 03:34 PM 0
Share

no it will keep you stuck around the square but if you wander which direction should platform take when you start & it didn't collided withe any of the 4 objects just put rb.velocity code in Start() since Start() only called once & send the platform to one of the 4 objects.

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

61 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 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 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

2D Top Down Character being Pulled down and movement script not working? 2 Answers

How to access two WheelJoint2D from C#? 0 Answers

how do I find out which object is closer to the finish line? 2 Answers

How do I create a grid-based map in the most efficient way? 2 Answers

Mouse Click Walk to Idle Animations 0 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