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 Loxli · Oct 14, 2013 at 05:55 AM · rotationcubewalking

Walking on a cube

Hi guys! I need to make my character walking on a cube like in this video http://www.youtube.com/watch?v=YYlGJoLUJVQ

I tried to use triggers and normal... but they don't work properly. Does someone have an idea or an example to do that?

I have only gravity at the center of the cube that is working fine :(

Regards!

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 Fikzy · Apr 16, 2014 at 07:10 PM 0
Share

I know this post is old but i'd like to know if you managed to make it work properly, cause i'm very interested in it ! :D

Thanks !

2 Replies

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

Answer by Marsupilami · Oct 14, 2013 at 11:52 PM

Follow this link CLICK ME and look for my posts at the bottom.

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 Loxli · Oct 15, 2013 at 02:41 AM 0
Share

Amazing script thank you so much!!!!

avatar image
1

Answer by phxvyper · Oct 14, 2013 at 06:43 AM

He modified or created his own FPSController. There are quite a few ways to do what he's doing. However, it is somewhat complex...

One way i can think of is:

Create a script that represents a point of gravity. When the Player Controller falls off of the side (it has no bottom trigger being triggered), make the Player Controller fall towards the point of gravity.

There may be a few more hoops you'd have to jump through, but this should lead you in the right direction.

Making the player fall towards a point is pretty easy. You can use quite a few number of methods, one of which would involve using Rotate and Translate (probably the easiest, but not always the best...)

Because you don't want to be using normal PhysX Gravity Physics for this, make sure that gravity is disabled in the Rigidbody's properties.

The code would look similar to this:

 /* C# */
 void Update() {
     //playerGrounded is a flag boolean that is true when the player is touching the ground, and false when the player is not touching the ground.
     if (!playerGrounded)
     {
         //Using LookAt and Vector3.Down, make the player rotate towards the point of gravity.
         //I wrote this code so that it will function if you have multiple points of gravity within the scene.
         //This also assumes that the object that represents the point of gravity has a script attached to it called "GravityPoint".
         
         //Find and cast every single GameObject of type GravityPoint.
         GameObject[] gravityPoints = (GameObject[])GameObject.FindObjectsOfType(typeof(GravityPoint));
         GameObject    closestGravityPoint; //This is the value that will be assigned the closest GravityPoint game object.
         if (gravityPoints.Length > 0) { //Make sure that there are gravity points in the scene.
             closestGravityPoint = gravityPoints[0]; //This is just used to assign any gravity point to closestGravityPoint.
             foreach (GameObject go in gravityPoints) { //Iterate through every gravity point.
                 //firstAndPlayer is the distance between the current object assigned to closestGravityPoint and the player.
                 float firstAndPlayer = Vector3.Distance(closestGravityPoint.transform.position, transform.position);
                 //goAndPlayer is the distance between the current object assigned to 'go' (the iterator) and the player.
                 float goAndPlayer = Vector3.Distance(go.transform.position, transform.position);
                 //Is go closer than the current value of closestGravityPoint? If so, assign the closestGravityPoint as go.
                 if (goAndPlayer < firstAndPlayer)
                     closestGravityPoint = go;
             }
             
             //Make the player rotate towards the closestGravityPoint's transform.
             //I use Vector3.forward as the 2nd parameter, the reason for this is
             //that the second parameter is what the up direction of the transform is, not the direction you want to look it.
             //Any Vector3 that only exists on the x or z axis will work for this, theoretically.
             transform.LookAt(closestGravityPoint.transform, Vector3.forward);
         }
     }
 }
 
 /* UnityScript */
 function Update() {
     if (!playerGrounded)
     {
         var gravityPoints : GameObject[] = GameObject.FindObjectsOfType(typeof(GravityPoint)) as GameObjects[];
         var closestGravityPoint : GameObject;
         if (gravityPoints.Length > 0) {
             closestGravityPoint = gravityPoints[0];
             for (var i = 0; i < gravityPoints.length; i++) {
                 float firstAndPlayer = Vector3.Distance(closestGravityPoint.transform.position, transform.position);
                 float goAndPlayer = Vector3.Distance(gravityPoints[i].transform.position, transform.position);
                 if (goAndPlayer < firstAndPlayer) {
                     closestGravityPoint = gravityPoints[i];
                 }
             }
             
             transform.LookAt(closestGravityPoint, Vector3.forward);
         }
     }
 }

You will also have to do some rotation correct for when playerGrounded = true so that the player doesn't have a sideways rotation.

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 Loxli · Oct 14, 2013 at 11:22 PM 0
Share

How can I make the player falling towards the point of gravity?

avatar image phxvyper · Oct 14, 2013 at 11:59 PM 0
Share

@Loxli check out the updated version of my post.

Theoretically, this should work. Also, check out marsupilami's answer.

avatar image Loxli · Oct 15, 2013 at 02:41 AM 0
Share

Now I can understand better how it works! thank you!

avatar image phxvyper · Oct 16, 2013 at 01:08 AM 0
Share

No problem! I'm glad i was able to help you understand the concept.

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

17 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

Related Questions

Rotating a created mesh around it's pivot 2 Answers

Walking animation following navigation 0 Answers

Measure a rotating gameobject. 0 Answers

Object rotation to exact degrees not working 3 Answers

How to have a cube to fall on fixed rotation? 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