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
0
Question by eventualni · Sep 22, 2012 at 05:32 PM · gravity

Attraction by object shape (gravity)

Hello, is there a chance that the player was attracted by the shape (mesh)?

for example: when you reach the edge of the cube you can go off the wall without falling and then go to the bottom of the cube (upside down).

If so, how do I do that?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Sep 22, 2012 at 09:20 PM

You will need a rigidbody character. I wrote a script times ago that allowed a rigidbody to walk upright over any surface - a local gravity pushed it towards the mesh under its feet, including in vertical or totally upside down surfaces. Take a look at my answer in this question.

Comment
Add comment · 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
0

Answer by Muuskii · Sep 22, 2012 at 06:07 PM

I just wrote this up without testing so take it with a grain of salt:

 Ray ray = new Ray(Vector3.zero, Vector3.forward);
 RaycastHit hitInfo = new RaycastHit();
 if(Physics.Raycast(ray, out hitInfo) )
 {
     Vector3 hitNormal = hitInfo.normal;
 }

What you could do is do a raycast towards the center of the cube and find the normal of the raycast hit like I show above. And then gravity = -hitNormal;

The gravity will always take your character towards the face of the cube he's standing on and if he falls off the edge it will take him above another face to stand on.

This "should" work for other shapes too.

Is this for a "minecraft planet"? I have to ask because I've wanted to see one. Without the motivation to actually do it :P

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 Muuskii · Sep 22, 2012 at 06:09 PM 0
Share

Small note: Putting the origin of your character's raycast at his feet will probably make this much better for what you're making.

Also; If you make the raycast only activate when the character is inside a trigger you can make sure to only do these tests when near an edge.

avatar image eventualni · Sep 23, 2012 at 07:48 AM 0
Share

Thank you very much! Yes, there is a concept of the '$$anonymous$$ecraft' world composed of cubes, after which the player can move through walls and ceilings. Game will be based on FPS shooter game :)

I'll check of the script tomorrow, because today, unfortunately, I have no way to do this :(

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

12 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

Related Questions

Character attract from magnet object 0 Answers

Changing gravity affecting 'random movement' behaviour script - my NPCs go crazy, what should I do? 1 Answer

Gravity.cs help? 3 Answers

Walking on walls JS 2 Answers

Artificial Gravity 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