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 Bindlestick · Sep 30, 2012 at 03:23 AM · platformersidescroller

Circular Platform

I am attempting to create a side scrolling 2.5 plat former, but instead of straight platforms, I'm thinking about creating one continuous plat former, or one that loops. How do I keep the character grounded so it won't fall off this circular platform?

Here's the script I have on my character as of now.

  var speed : float = 6.0;
     var jumpSpeed : float = 8.0;
     var gravity : float = 20.0;
     
     private var moveDirection : Vector3 = Vector3.zero;
     
     
     function Update () {
         var controller : CharacterController = GetComponent(CharacterController);
         if (controller.isGrounded) {
     
             moveDirection = Vector3(0,0,Input.GetAxis("Horizontal"));
     
             moveDirection *= speed;
             
         if (moveDirection.sqrMagnitude > 0.01)
             transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (moveDirection), 1);
             
             if (Input.GetButton ("Jump")) {
                 moveDirection.y = jumpSpeed;
             }
         }
         
         moveDirection.y -=gravity * Time.deltaTime;
         
         controller.Move(moveDirection * Time.deltaTime); 
     
     }
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
0

Answer by gregzo · Sep 30, 2012 at 09:07 AM

If I understand you well, you want your level to be a circular strip? Seen from above : o ? Player moving clockwise or counter clockwise?

If that's the case, you could make the player object a child of an empty object which is centered at the center of the circle.

When you want the player to move along the y axis, move it's parent instead.

When you want the player to move horizontaly, rotate his parent instead.

Does it help?

Comment
Add comment · Show 1 · 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 Bindlestick · Sep 30, 2012 at 05:33 PM 0
Share

Yes, correct. I guess gravity would be the correct problem of this then. Basically the platform is a cylinder turned on its side, so all the player would see is a circle with the player on top. Here's a link that basically sums up what I'm thinking about, besides the 2 other platform.

http://www.youtube.com/watch?v=qz8mFZczu$$anonymous$$0

Thanks for the answer.

avatar image
0

Answer by Bindlestick · Sep 30, 2012 at 10:49 PM

Thanks. For your recent advice, I've been having partial luck. The character is facing the center of the circle, but I'm having trouble having his bottom facing the center. I guess that can be fixed by messing with the x, y and z of one of the coding I've added. I'm also having trouble with the transformDirection code, the "Object reference not set to an instance of an object" error.

 var characterlook : Transform = target.transform;
 
 var charRelativeRight : Vector3 = characterlook.TransformDirection (Vector3.right);
 
 rigidbody.AddForce (charRelativeRight * 10);

  

      var target : Transform; 
 
 function Update () {
     
     // Rotate the camera every frame so it keeps looking at the target 
     transform.LookAt(target);
 }
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

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

11 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

Related Questions

Contrain movement along x axis 1 Answer

2.5D Platformer Camera follow character Y axis but not for every jump? 1 Answer

Question About Raycast and Sidescrollers 0 Answers

Using rigidbody to push and pull Platform Controller 0 Answers

2D - Detect Slopes x Walls 1 Answer


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