Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

First Person Controller

Discussion in 'Editor & General Support' started by Thomas-Pasieka, Jul 14, 2006.

  1. Thomas-Pasieka

    Thomas-Pasieka

    Joined:
    Sep 19, 2005
    Posts:
    2,174
    Hi there folks,

    I was just wondering what I need to do in order to use this premade camera (First Person Controller) to actually affect other objects. Let's clarify this a bit. I want to use this controller to run into things like boxes. These boxes of course need to be pushed or fall once I run into them. Right now they don't react at all and since I am a non-coder I am not sure what to do :) Any help?

    Thomas


    Edit: fixed the subject.
     
  2. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    It seems to be done with a capsule collider usually.

    If you want a really simple example, simpler than the full FPS tutorial, look here:

    http://unity3d.com/examples

    Download the old "Physics Demo"--it contains a scene called "fps playground" that is pretty basic but it has boxes you run into and knock down with physics.

    (Also, in "Other Examples" on that page are some other little scenes, including "First Person Movement.")

    Hopefully you'll find some useful code to start from there.
     
  3. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
  4. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,553
    Flamin heck!
    I just typed up a full detailed how to and my computer crashed...

    The short version is this:

    go New scene add a plane(to walk on) a cube(to push)
    and a fps controller prefab

    add a collider to each,(mesh collider to plane, box collider to cube-these may appear by default)

    add a rigidbody to the cube
    And you should be away...

    Let us know how you get on.

    Fear not the scriptlords-they sleep better when they've fed their minions lots of helpful little scripts...

    Thank you you know who you are

    AC :twisted:
     
  5. Thomas-Pasieka

    Thomas-Pasieka

    Joined:
    Sep 19, 2005
    Posts:
    2,174
    Thanks for your answers guys. I still can't get it to work properly. It seems like I get random results with it. The first person controller has two child objects (Graphics and main camera). I need to add a collider to the "Graphics" and the "parent"? I just tried it by only adding these components to the "Graphics" object but that didn't work. I then placed a colider and rigidbody to the "parent" object and then it works (well not always). I must be doing something wrong. Maybe I am not understanding it fully here.

    Thomas
     
  6. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    i don't know much about the fps tut and this is all iirc but

    >>I need to add a collider to the "Graphics" and the "parent"?
    no. add a rigidbody to the cube you want to push. iirc the fps controller doesn't use a rigidbody or collider at all.

    if you look at the hierarchy of the fps tut it's parented as
    >first person controller
    >>graphics
    >> main camera
    >>> weapons

    none have colliders or rigidbodies attached. it uses a character controller instead which i think basically has the equivalent of a capsule type collider built in (not sure exactly). height and radius will affect it's size. if you need more accurate collision (ie pushing the box with a hand) you'll need to build it differently. maybe by attaching a physics rig (game empties with colliders attached) to a ragdoll or your animated model. you can still use the walker script but you'll need to write your "push" script. hth
     
  7. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,553
    or you could start from scratch. Add Cube, capsule, plane. put the camera right at the top of capsule, and parent by dragging the camera onto the capsule in the hieracy window.Add a rigidbody to both capsule and cube, add the fps walker script to the capsule, and try dragging the mouselook(look in project window, in camera scripts)script from the project window onto either the camera or the capsule.

    Try not to add too much other stuff as sometimes the bits and pieces can sort of contradict each other
    AC
    Hey Pete what does hth mean?
     
  8. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Here is an fps walker that pushes rigidbodies.

    To use it, find the FPS walker in:
    "Standard Assets/Scripts/FPSWalker.js"

    and replace the script with the one attached to the post.

    You also have to assign a rigidbody to all objects that you want to be pushable.
     

    Attached Files:

  9. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    hth = hope this helps