Search Unity

Parkour System?

Discussion in 'Scripting' started by BusterBlader, Nov 18, 2012.

Thread Status:
Not open for further replies.
  1. BusterBlader

    BusterBlader

    Joined:
    Apr 23, 2012
    Posts:
    79
    Hey,

    I want to create a simple FPS Parkour System. I have a capsule which has a Character Controller with simple Controls. Now if the capsule stands in front of an obstacle tagged "Obstacle" and the player presses Space i want the capsule to slide over the obstacle. But i don't know how to achieve it.

    I hope you can help me :)

    Greetings
    BusterBlader
     
  2. Steve Steven

    Steve Steven

    Joined:
    Nov 18, 2012
    Posts:
    4
    This is called Behavior!
    This is many lines of code in Unity3d, In other game engines this is more simple.
    As first use Locomotion, which is developed by Unity3d Support Team and you can use for feet animation.
    As second use Head Look Controller, which is also developed by Unity3d Support Team and you can use for head animation.
    For the rest of behavior If you have money to spend I suggest you to buy "Character System v2"
    This is the intro video and this is the complete showcase.
    If you need more help, let me know.
     
  3. Democre

    Democre

    Joined:
    Mar 31, 2010
    Posts:
    345
    Or if you are using Unity 4, you could follow the mecanim tutorial, which I believe covers something similar enough to get you where you want.
     
  4. BusterBlader

    BusterBlader

    Joined:
    Apr 23, 2012
    Posts:
    79
    Thanks...but...i think you didn't understand what i want to achieve. I don't want to animate anything. I just want to let the capsule slide over the obstacle like in many other FPS Games ;)
     
  5. Democre

    Democre

    Joined:
    Mar 31, 2010
    Posts:
    345
    If you don't want to use mecanim, that's fine. Just watch the mecanim tutorial for its use of triggers (ignore the animation bits), you'd want something similar.
    Basically put a collider trigger in front of whatever obstacle you wish and whenever the player enters the trigger, set some flag that allows for moving over the obstacle, and set the flag to false when exiting the trigger.
    Code (csharp):
    1. //ObstacleTrigger.js
    2. function OnTriggerEnter (other : Collider) {
    3.    var player = other.GetComponent("Player") as Player;
    4.    if(player != null) {
    5.       player.crossableObstacle = this.transform;
    6.    }
    7. }
    8.  
    9. function OnTriggerExit (other : Collider) {
    10.    var player = other.GetComponent("Player") as Player;
    11.    if(player != null) {
    12.       player.crossableObstacle = null;
    13.    }
    14. }
    Code (csharp):
    1. //Player.js
    2. var obstacle : Transform;
    3.  
    4. function Update() {
    5.    if (obstacle != null  Input.GetKeyUp( KeyCode.Space )) {
    6.       // code to face the direction of obstacle, determine it's height, and move the camera over
    7.       //or whatever
    8.    }
    9. }
     
  6. nullstar

    nullstar

    Joined:
    Jul 2, 2010
    Posts:
    186
    This is kinda the wrong way to think about making these systems. The better way is to have your characters motion driven by the animation and the players inputs and characters relation to their environment control which animations to play. So for example you would have a run animation and a vaulting animation. When the player pushes the joystick it plays the run animation and the characters position is directly updated from this animation and when the character is close enough to an object it can vault your system then switched to the vault animation and your characters position is driven by that animation instead. Games like this are usualy built with quantised environments, so for example you would build all your obstacles to match a small set of pre-determined heights and widths and you would have a vault animation set up for each. Alternatively you could build several vault animations for low, medium and high vaults for example and then blend between them to achieve the desired vault height.
     
  7. BusterBlader

    BusterBlader

    Joined:
    Apr 23, 2012
    Posts:
    79
    Thanks Democre :) But the thing i don't know how to do are the motions of the capsule.
     
  8. Democre

    Democre

    Joined:
    Mar 31, 2010
    Posts:
    345
    The capsule collider is handled specifically in the mecanim tutorial.
     
  9. BusterBlader

    BusterBlader

    Joined:
    Apr 23, 2012
    Posts:
    79
    Thanks :) I'll try mecanim tomorrow ;) It's 10pm over here
     
  10. Steve Steven

    Steve Steven

    Joined:
    Nov 18, 2012
    Posts:
    4
    Yeah "nullstar" is right, I said Locomotion System and Head Look Controller System because is the best way to start to create something own. But now there is also Mecanim, which is complete of anything.
     
  11. BusterBlader

    BusterBlader

    Joined:
    Apr 23, 2012
    Posts:
    79
    Oh sorry :D Haven't seen nullstars post ;) Yeah i checked Mecanim and tested the Example Scenes :D I really like it and i think it's the stuff i need :D
     
  12. Matheusfig

    Matheusfig

    Joined:
    Nov 24, 2012
    Posts:
    5
    See The Script:

    Code (csharp):
    1. var Hand : GameObject;
    2. var UpPlataformName = "";
    3. var CanUpPlataform1 = false;
    4. var CanUpPlataform2 = false;
    5. var CanDoubleJump = false;
    6. var Range = 1.5;
    7. var canTranform = false;
    8.  
    9. function Update () {
    10.  
    11. var hit : RaycastHit;
    12. var Direction = transform.forward;
    13.  
    14. if(Physics.Raycast(transform.position, Direction, hit, Range)){
    15. if(hit.collider.gameObject.tag == "Up1"){
    16. CanUpPlataform1 = true;
    17. }
    18.  
    19. if(hit.collider.gameObject.tag == "Up2"){
    20. CanUpPlataform2 = true;
    21. }
    22.  
    23. if(hit.collider.gameObject.tag == "Untagged"){
    24. CanDoubleJump = true;
    25. }
    26.  
    27. }
    28.  
    29. if(Input.GetKeyDown(KeyCode.Space) CanUpPlataform1 == true){
    30. transform.position.y += 1.5;
    31. transform.position.z += 0.5;
    32. audio.Play();
    33. CanUpPlataform1 = false;
    34. }
    35.  
    36. if(Input.GetKeyDown(KeyCode.Space) CanUpPlataform2 == true){
    37. transform.position.y += 0.7 ;
    38. audio.Play();
    39. CanUpPlataform2 = false;
    40. }
    41.  
    42. if(Input.GetKeyDown(KeyCode.Space) CanDoubleJump == true){
    43. canTranform = true;
    44. transform.Rotate(0, 180, 0);
    45. if(canTranform == true){
    46. transform.Translate( 0, 5, 0);
    47. transform.Translate(0, 0, 10 * Time.deltaTime);
    48. }
    49. audio.Play();
    50. CanDoubleJump = false;
    51. }
    52.  
    53. }
    54.  
    55. function OnCollisionEnter(col : Collision){
    56. canTranform = false;
    57. }
    if you like Use this


    use it for audio:

    http://www.mediafire.com/?0z6q9hdfxpkn0ur

    OBS: I'm Brasilian and I have a bad english
     
    Last edited: Jan 4, 2013
  13. djary

    djary

    Joined:
    Oct 17, 2012
    Posts:
    85
    u say : can create parkour system with mecanim ?
     
  14. seb-lopez

    seb-lopez

    Joined:
    Feb 12, 2013
    Posts:
    1
    wow your script is cool Matheusfig but the scripts deactivate when pressing one time on the space . Please help its the closes script that almost work for the obsticle game :(
     
Thread Status:
Not open for further replies.