Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

First-Person Hollow Sphere World

Discussion in 'Physics' started by s-elliot-perez, Jan 12, 2017.

  1. s-elliot-perez

    s-elliot-perez

    Joined:
    Mar 4, 2016
    Posts:
    22
    Hello,

    I'm trying to create a 'simple' game inside a sphere, so the player can look around and change her walking direction with the mouse and move with the horizontal and vertical control axes. I seem to have succeeded in creating the sphere itself by modelling it in Maya with the normals reversed, importing it into Unity with "Generate Collider" checked and NOT checking 'convex' on the mesh collider - in normal gravity and with a normal controller, I can walk around in the bottom half like a basin.

    The problem is getting a good character controller that works with an appropriate gravity script. I've done a lot of searching and found some similar topics. This one offers a gravity script, but the poster says that the Unity character controller, which would otherwise be a great set-up for what I want, is not rotatable: https://forum.unity3d.com/threads/solved-player-rigidbody-walking-around-planet.256006/

    This topic contains (at the very end) the same gravity script a and a 3rd person walker script for walking on the outside of the planet, but when I attach them to the Unity RigidbodyFPS controller, I can't move, maybe because it's the wrong perspective: https://forum.unity3d.com/threads/solved-player-rigidbody-walking-around-planet.256006/

    Please let me know if you have any tools to help me solve this. As you can see, I'm a beginner. I've been doing Unity/C# tutorials for a couple of months and want to try actually making something, but this hollow sphere idea is giving me a hard time.

    Thanks in advance.
     
  2. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    I am not sure, but possibly you should make the sphere to rotate so the fps controller would always stay at the bottom of the sphere.
     
  3. Shodan0101

    Shodan0101

    Joined:
    Mar 18, 2013
    Posts:
    140
  4. s-elliot-perez

    s-elliot-perez

    Joined:
    Mar 4, 2016
    Posts:
    22
    Hey, thanks for your replies. @tomekkie I tried that, though the problem was setting up the controls. The point of orientation is the player, but when you rotate the sphere along one axis, it changes the direction of its other axes, so the controls affect it differently.

    Someone else gave me the idea to attach the player to an object in the middle of the sphere and rotate said object. This is working well.
     
  5. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    Just wondering - means the player doesn't stay vertical?
    Are you still using the Unity character controller?
     
  6. s-elliot-perez

    s-elliot-perez

    Joined:
    Mar 4, 2016
    Posts:
    22
    No, the Unity Assets Character Controllers are very complex and conceived for regular gravity, so I made a new script (borrowing a lot from the Unity scripts, e.g. the functions for locking range when looking around with the mouse), attached it to the parent object in the center of the sphere, which has as children the player rigidbody and camera.
     
  7. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    So what happens if your player encounters an obstacle or an upward or downward slope over the spherical base surface - or you just simply didn't need support for anything like that.
     
  8. s-elliot-perez

    s-elliot-perez

    Joined:
    Mar 4, 2016
    Posts:
    22
    Because there's a rigidbody attached to the player, obstacles should still stop him. I don't (yet) plan on having any slopes, but it's a good question. It's been suggested to me that, if I want to allow the player to jump, I could implement a SpringJoint component. This might work with slopes too, but I haven't learned how to use it yet.
     
  9. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    Possibly the simplest could be to cast a ray from the player position to your spherical terrain and then correct the player position along the radius to ensure it stays within some given range.
     
  10. s-elliot-perez

    s-elliot-perez

    Joined:
    Mar 4, 2016
    Posts:
    22
    OK, thanks. I've only been exposed to RayCasting in the Survival Shooter tutorial, so I'm not exactly proficient... but if/when I need to try another approach, I'll look up a RayCasting tutorial and get back to you.