unity3d - Unity - Walk around a cube -


i have issue trying 'object(character)' walk around cube (all sides) within unity. ive attached image , video showing trying achieve. im trying show visually rather trying explain. character drops on edge rotates 90 degrees , stands gravity has switched. character can jump walk etc.

this example of else posted video showing im trying achieve

i have looked through forums , cant find im after. have tried attach diagram site wont let me. advice appreciated!

regards

nick

you have couple of options can think of.

one trigger gravity change when character exits 1 face of cube go another. achieve have trigger zones on each edge , face , use [bob went face edge anorth -> switch gravity go in x direction].

this work situations gravity switch must affect other objects advantageous player (walking off side makes enemy fall off , die - example.)

however, if want entities stick relative sides need make custom gravity! easier might think gravity downward accelleration of 9.8. turn off engines native gravity , create "personal gravity" component:

private vector3 surfacenormal; private vector3 personalnormal; private float personalgravity = 9.8f; private float normalswitchrange = 5.0f;  public void start() {         personalnormal = transform.up; // start "normal" normal     rigidbody.freezerotation = true; // turn off physics rotation     }  public void fixedupdate() {     // apply force taking account character normal personal gravity:     rigidbody.addforce(-personalgravity * rigidbody.mass * personalnormal); }  

rotating character , changing normal suit situation or game mechanic, whether raycasting if you're standing on surface detect when change or want gravity change when hit powerup or similar - experiment , see works. comment more if have questions!

edit:

as addition video linked. can keep state variable on jump state , raycast in each axis direction check face nearest in case of rolling off.

public void update() {     // don't update personal normals in case of jumping     if(!jumping)     {         updatepersonalnormal();     }  }  public void updatepersonalnormal() {     raycasthit hit; //hit register     // list of valid normals check (all 6 axis)     ray[] rays =          {         vector3.up, vector3.down,          vector3.left, vector3.right,          vector3.forward, vector3.backward         };      //for each valid normal...     foreach(ray raydirection in rays)     {         //check if near cube face...         if(physics.raycast(raydirection , hit, normalswitchrange)         {              personalnormal = hit.normal; //set personal normal ...              return; // , return done         }     } } 

please keep in mind above hand written , not tested play , pseudo start should give idea of do.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -