• 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 Adamsw216 · Nov 29, 2009 at 05:44 AM · gameobject

How do I write a script so that an object rotates and follows the contours of a larger object?

First, I am newer to scripting than most of the people here that also make such claims. So basically, I would like to be able to walk around the inside circumference of a cylinder with an FPS controller. Is it possible to write a script that keeps the moving object "grounded" (perpendicular) to the geometry of the cylinder? Another example of what I'm looking for could be applied to: driving a car through a vertical loop.

I have no idea where to even begin scripting anything like this.

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 cregox · Feb 20, 2010 at 03:09 AM 0
Share

I feel your pain. I actually want basically the same thing: http://answers.unity3d.com/questions/3378/physics-objects-in-a-curved-2d-plane Rather than a loop it's even simpler in a way. It's "just" a curve. Just want to tell you I think there is no simple answer for this one. :(

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Stelimar · Nov 29, 2009 at 07:29 AM

From the collision object passed to the OnCollisionStay event, you can access a list of contacts, and get their normals. However, there could potentially be multiple contacts, which means you'll have more than one normal. To deal with this, I would simply add the normals together, and normalize, which would give you something like this:

function OnCollisionStay(col : Collision) {
    var colNormal : Vector3 = new Vector3();
    for (var contact : ContactPoint in col.contacts) {
        colNormal += contact.normal;
    }
    colNormal.Normalize();
    transform.up = colNormal;
}
Comment
Add comment · Show 4 · 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 Adamsw216 · Nov 29, 2009 at 08:07 AM 0
Share

Thank you for your help! But, I'm not exactly sure what I am supposed to do. I attached the script to the cylinder... then how do I access the list of contacts and link that with the FPS controller?

avatar image Adamsw216 · Nov 29, 2009 at 08:08 AM 0
Share

I am also getting a few errors from the code:

(Filename: Assets/colnorm.js Line: 1)

Assets/colnorm.js(1,23): BCE0043: Unexpected token: Collision.

(Filename: Assets/colnorm.js Line: 1)

Assets/colnorm.js(2,5): BCE0043: Unexpected token: var.

(Filename: Assets/colnorm.js Line: 2)

Assets/colnorm.js(2,8): UCE0001: ';' expected. Insert a semicolon at the end.

(Filename: Assets/colnorm.js Line: 2)

Assets/colnorm.js(2,9): BCE0044: expecting EOF, found 'colNormal'.

avatar image cregox · Feb 20, 2010 at 03:06 AM 0
Share

@Stelimar: Well, he said he knew absolutely nothing about script. This answer was really not for you, @Adamsw216. It's quite technical. :P

avatar image cregox · Feb 20, 2010 at 03:11 AM 0
Share

By the way, that script is just a guideline and a part of what would go on the FPS Controller object - not the cylinder.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

OnCollisionEnter GameObject throws NullReferenceException 0 Answers

Alternative way of accessing other scripts? 2 Answers

Don't Destroy on Load Object and GameData 1 Answer

"Transform" still trying to access after Destroy 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