Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 ToeBeanGames · Aug 09, 2015 at 02:44 AM · physicsrigidbodygravity

Movement on a tube

I'm working on a game similar to Sonic Lost World, and I need to get the movement on a tube-like level like in that. I've tried turning off physics and seeing the gravity to always be downwards relative to the player, and unfortunately that didn't work. The closest thing I can find to this problem is moving on a sphere like in Mario Galaxy, which doesn't work at all with the tube-like level because the player will just gravitate towards the level's pivot point instead of keeping the mesh upright at any angle.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by sparkzbarca · Aug 09, 2015 at 02:56 AM

raycast down. get the terrains normal, use the terrains normal (which will be your up) + the characters transform.right in a vector.cross(..) to get the new transform.lookat(...) That will allow you to always be "level" on the ground.

for a brief PSEUDO code example

UPDATED

 Vector3 Right = transform.right;

 RaycastHit Hit;

 Physics.Raycast(transform.position,-transform.up, out Hit)

 Vector3 Up = Hit.normal;

 Vector3 Forward = Vector3.Cross(Right,Up);
 
 Vector3 LookPos = transform.position + Forward;
 
 Void Update()
 {
 transform.Lookat(LookPos);
 }

Message if you need any help understanding or coding.

Comment
Add comment · Show 8 · 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 ToeBeanGames · Aug 09, 2015 at 03:06 AM 0
Share

It's giving me issues with Up because hit isn't a bool.

I can't copy and paste anything because I don't have any internet on my computer and am posting from my phone.

avatar image ToeBeanGames · Aug 09, 2015 at 03:13 AM 0
Share

$$anonymous$$ore specifically, it says "Type 'bool' does not contain a definition for 'hit' and no extension method 'hit' of type 'bool' could be found."

avatar image sparkzbarca · Aug 09, 2015 at 03:27 AM 0
Share

yea i already changed it, though again thats pseudo code but yea see the new code. there is not .hit. just straight to .normal.

oh whoops noticed another thign im goign to update the code again in a $$anonymous$$ute :P you'll ahve to pass the raycast out to a hit variable I forgot that unique part of raycast whoops. :P

avatar image ToeBeanGames · Aug 09, 2015 at 03:29 AM 0
Share

It still says 'System.Boolean' does not contain a definition for 'normal'

avatar image sparkzbarca · Aug 09, 2015 at 03:31 AM 0
Share

updated now, forgot raycast returns a bool not the hitinfo and you have to send in a variable its stored in, its updated now.

Show more comments

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

24 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

Related Questions

Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 Answers

Where is the general Rigidbodies Drag? 3 Answers

Player in Spaceship 2 Answers

How To Set Individual Rigidbody Gravity [Solved] 3 Answers

Rigidbodies getting stuck in non moving objects 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