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 dreDREb13 · Oct 10, 2013 at 09:22 AM · gravity

How to set a player's gravity relative to a mobius strip?

So I'm creating an experimental game in which the player may travel endlessly on a mobius strip. I got it all rendered in Blender, threw it into Unity, but then I realized a new problem: I'm not sure how to get gravity to function for this thing.

Anyone got any tips or scripts that I could use to keep a player grounded to the thing without having to climb up or fall down any curves?

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 Fattie · Oct 10, 2013 at 12:36 PM 0
Share

this question seems to come up all the time. Really someone should make a good "surface sticker" !

Here for example is one of many ludicrously long arguments about it, @dre

http://answers.unity3d.com/questions/545844/make-player-character-stick-to-the-level-mesh-and.html

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Marsupilami · Oct 11, 2013 at 11:18 AM

Turn off gravity on the player's rigidbody.

Raycast down from player to get the normal of triangle hit and align player to that normal. Ensure the surface of your Mobius does NOT have triangles that are too big. You want them to be on average about the size of 1 Unity unit (1 meter) or less.

 RaycastHit hit;
 if (Physics.Raycast(transform.position, -transform.up, out hit)) {
 transform.rotation = Quaternion.LookRotation(Vector3.Cross(transform.right, hit.transform), hit.transform);
 }

Apply a downforce relative to players transform. Make gravitySpeed public and adjust accordingly.

 rigidbody.AddForce(-transform.up * Time.deltaTime * gravitySpeed);
Comment
Add comment · Show 6 · 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 Fattie · Oct 11, 2013 at 11:24 AM 0
Share

"Raycast down" how ?

You can't .. it's an AI question at best.

there's a huge discussion about it here

http://answers.unity3d.com/questions/545844/make-player-character-stick-to-the-level-mesh-and.html

the scheme you describe is how normal say car race titles (on relatively flat, sedate, surfaces) work

avatar image Marsupilami · Oct 11, 2013 at 11:27 AM 0
Share

Raycast down from the current rotation. This can be improved by adding additional raycast at various angles and using the result with the least distance to deter$$anonymous$$e the closest mesh triangle.

You could even use the 2 smallest distances and combine the 2 to create a smooth transition for sharper angles.

It all comes down to creating a solution that fits the situation. I think a relatively large $$anonymous$$obius with sufficiently populated mesh can be done with 1 raycast. Using 13 raycasts, I believe you could attach to even the most complex mesh.

avatar image Marsupilami · Oct 11, 2013 at 11:35 AM 0
Share

If you want a real fully coded example ins$$anonymous$$d of learning and experimenting, drop me the $$anonymous$$obius model and I'll whip up an example.

avatar image Marsupilami · Oct 11, 2013 at 01:38 PM 0
Share

I was able to do this $$anonymous$$agic Boots with $$anonymous$$imal coding and only 3 spherecast. It even has jumping. Not too far stretch to polish this to work on just about any surface and have it able to drop into any character and work.

avatar image Marsupilami · Oct 11, 2013 at 02:11 PM 0
Share

Was able to preserve the same integrity of the above video using a single spherecast.

 RaycastHit hit;
 if (Physics.SphereCast(transform.position, 0.5f, -transform.up, out hit, 5))
 {
     transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.Cross(transform.right, hit.normal), hit.normal), Time.deltaTime * 5.0f);
 }        
 rigidbody.AddForce(-transform.up * Time.deltaTime * gravitySpeed);
Show more comments
avatar image
0

Answer by DaveA · Oct 10, 2013 at 09:28 AM

Instead of attracting the player to the strip, can you rotate the entire world/strip under the player? Then it would be finding the normal of the poly you want your feet on, and aligning the strip's Up axis with that.

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 dreDREb13 · Oct 11, 2013 at 09:23 AM 0
Share

I thought about that, but I've got the extra issue of being fairly new to Unity, and I'm still building my coding knowledge and ability at this point.

Do you think that the script would be a bit too complicated to figure out at this point? I looked through the thread Fattie sent me, but most of it seemed to be conjecture and arguments as to what would work best. There was an explanation of how it could work, but it's all going a bit over my head.

Thanks for taking the time to help me out, and I apologize for my inexperience.

avatar image Fattie · Oct 11, 2013 at 09:25 AM 0
Share

Sure, it would be quite difficult. Why not try a simpler example game first? Do something on a flat surface.

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

18 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

Related Questions

Bike wobbles like pendulum after applying gravity 1 Answer

Js: UnityEngine.Rigidbody is required, how to fix? 2 Answers

How to set gravity for model? 1 Answer

Why can't I move along the Y axis when I shift gravity from the Y to Z axis? 1 Answer

Character teleports to the apex of full jump height 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