Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I make 3D Platformer controller like the old N64 games?

Discussion in 'Scripting' started by Bryan77, Jun 26, 2015.

  1. Bryan77

    Bryan77

    Joined:
    Jun 9, 2014
    Posts:
    24
    Hello. I am a beginner when it comes to scripting, as I am mostly an animator. I am trying to get a character to move around like a 3D platformer. Meaning, when I press "w" I want to go forward in relation to the camera. If I press "a" I want my character to go left, in relation to the camera (and so on) I also want my character to face in the direction that he is moving. I don't like how mecanin has the animation drive the movement, because if I change the animations that will mess everything up. Also, the example controllers that Unity uses control very clunky. I also need to jump. I haven 't been able to find a tutorial on this type of control. Would someone be able to help me figure this out?


    A related question (Which might be better asked in a separate thread,) is how I can have the camera be controlled with the mouse.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you don't have to use root motion in the mecanim animators.

    basic movement and camera control is covered in the learn section tutorials... might be worth looking at them and if you get stuck on something a little more specific posting back here. Jump is "just" a vertical force added when the play presses the control, again basic user input is covered in the tutorials.

    http://unity3d.com/learn/tutorials/modules
     
  3. Bryan77

    Bryan77

    Joined:
    Jun 9, 2014
    Posts:
    24
    Yes, I have been looking at the learn section for the past week, and the best I can come up with is having forces acting like he's on ice, and tank controls. Neither of which work in relation to the camera

    This tutorial looks like it could be good, except that when you look at the script you see he is calling the animations, and not moving the character, meaning that he is having root motion (which is not what I want, also its in unity 4, which seems to have problems when I try to put those scripts in Unity 5)
    http://unity3d.com/learn/tutorials/projects/stealth/player-movement

    Maybe I'm looking at the wrong places.
     
  4. 1Piotrek1

    1Piotrek1

    Joined:
    Mar 14, 2014
    Posts:
    130
  5. Bryan77

    Bryan77

    Joined:
    Jun 9, 2014
    Posts:
    24
    1Piotrek1,

    Thank you for the reply. That is much closer to what I am looking for! I like how it handles, in that it quickly accelerates, and decelerates on stop, as opposed to the icy movement that comes with rigid bodies (as seen in the Roll-a-Ball tutorial) How would I get my character to turn in the direction of his movement?

    Also, I don't understand what you mean about my movement should be relative to world, and not the camera. All the old N64 games had controls relative to the camera.

    this is the sort of thing I'm looking for.
     
    Last edited: Jun 26, 2015
  6. Bryan77

    Bryan77

    Joined:
    Jun 9, 2014
    Posts:
    24
    Does anyone else have any ideas on how to get this sort of setup? I can't see how it would be too hard, as it is an old control scheme.

    here is another example of the kind of controls I want.
     
  7. 1Piotrek1

    1Piotrek1

    Joined:
    Mar 14, 2014
    Posts:
    130
    If you want to make movement relative to camera transform you should write
    YourCController.Move(Camera.main.transform.TransformDirection(new Vector3(Input.GetAxis("Horizontal"), 0, (Input.GetAxis("Vertical")));
    But if your camera (object that character movement will be relative to) have x or z rotation the movement will look weird.
    And for rotation:
    transform.LookAt(transform.position+Camera.main.transform.TransformDirection(new Vector3(Input.GetAxis("Horizontal"),0, Input.GetAxis("Vertical"))));
     
    Last edited: Jun 29, 2015
  8. Bryan77

    Bryan77

    Joined:
    Jun 9, 2014
    Posts:
    24
    I feel dumb, as I am still very confused as to what I am supposed to do. I tried putting that new script into the character script, and nothing happens. I also tried putting it on the camera, and still nothing happens. Looking at it, I see that it is missing a few close parentheses. Also, what is it supposed to be doing? Is it just getting the direction of the camera? How would I apply that to a character?

    I was talking with some programmers, and they suggested that I get the local coordinates of the camera, and then apply them to the world coordinates of the character. I don't know how I would go about doing this.

    I mentioned in my first post that I'm an animator, and not a coder. so maybe I'm wasting my time trying to get my guy to move around on screen. Even the people I was talking with, thought that the control that I am going for (N64 style platformers) was a hard thing to do. I find that ironic as those were some of the first 3D games.
     
    Last edited: Jul 3, 2015
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    It's not that hard. Moving an object around relative to the direction of the camera is easy. Interfacing with physics and/or a character controller and/or animation makes it more complex.

    So, to pursue this, I think you need to break it down into smaller, more bite-sized chunks:
    • How do I determine what directions in the world correspond to left/right/forward/back on my controller?
    • How do I move an object in any given direction in the world?
    • How do I turn a character controller toward a given direction in the world?
    • How do I make my character run and jump in the direction he's facing?
    I hope you can see how, once you have mastered all four of these questions, putting them together for a complete solution should be quite straightforward. But tackle them separately first... and maybe start a new thread for each one that you get stuck on!
     
  10. Bryan77

    Bryan77

    Joined:
    Jun 9, 2014
    Posts:
    24
    Thank you for the suggestion Joe. I think that's a great idea to break it down in that way. I can see how doing that would also give me a much better understanding of programming overall.
     
  11. 1Piotrek1

    1Piotrek1

    Joined:
    Mar 14, 2014
    Posts:
    130
    So, to make that script work you must attach them to gameobject with character controller, and have camera tagged as main camera on scene.
    The first part of script is the same as script from my previous post but i changed world coordinates to main camera local using.TransformDirection. This function is used in for example standard asset's first person controller, so it should work.
    The second part was tested by my, and it rotating my player perfectly.
    You can try this script without all this TransformDirection functions,maybe this is the problem.