Search Unity

Little bit of help? 2.5D platformer problems

Discussion in 'Scripting' started by ceriux, Oct 10, 2015.

  1. ceriux

    ceriux

    Joined:
    Mar 9, 2013
    Posts:
    2
    Hey so I'm New to unity and to start I chose to follow a tutorial on YouTube. ( this one ) Anyways I strayed a little bit from the tutorial not much really , basically the player is a cube in the tutorial.. I used the same cube but chose not to render it (just use it as a bounding box for the player) instead I made a 3D plane made it a child of the player cube and also made the camera a child of the same cube. That way I could instead us a 2D sprite as my player object and have the camera follow the player. But! here is my problem. When ever I hit a wall even just a little bit, I can no longer jump. I'm only aloud to walk left to right jumping no longer works.

    any help would be appreciated. thanks .
     

    Attached Files:

  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Did you make sure to add a physics material on your player collider with 0 friction, as well as setting its friction combine to minimum if your collider is a 3d collider?
     
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Post your movement/jumping script (use code tags). If jumping works normally except when you are touching a wall there is probably some sort of check being done that disables the jump in certain conditions e.g. If the wall is tagged as a wall perhaps jump is disabled when the player is touching it to prevent wall/double jumping.

    Also, did everything work before you changed things?
     
  4. ceriux

    ceriux

    Joined:
    Mar 9, 2013
    Posts:
    2
    yes, it works the same even if I render the cube and do not attach the children.

    its a bit sloppy :

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7. //movement
    8. public float speed;
    9. public float jump;
    10. float moveVelocity;
    11.  
    12. //Grounded Variables
    13. bool grounded = true;
    14.  
    15. // Update is called once per frame
    16. void Update ()
    17. {
    18. //jumping
    19. if (Input.GetKeyDown(KeyCode.W))
    20. {
    21. if (grounded)
    22. {
    23. GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jump);
    24. }
    25. }
    26.  
    27. moveVelocity = 0;
    28. //left and right
    29. if (Input.GetKey (KeyCode.A))
    30. {
    31. moveVelocity = speed;
    32. }
    33. if (Input.GetKey (KeyCode.D))
    34. {
    35. moveVelocity = -speed;
    36. }
    37.  
    38. GetComponent<Rigidbody2D> ().velocity = new Vector2 (moveVelocity, GetComponent<Rigidbody2D> ().velocity.y);
    39.  
    40.  
    41. }
    42.  
    43. // Check if grounded
    44. void OnTriggerEnter2D()
    45. {
    46. grounded = true;
    47. }
    48.  
    49. void OnTriggerExit2D()
    50. {
    51. grounded = false;
    52. }
    53.  
    54.  
    55. }
    56.  
     

    Attached Files:

  5. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Put a breakpoint on the if(grounded) part of the jump & then see what the value is when you press the jump key. If jump is false you will need to work out why as you are only setting it to false when nothing is touching the collider.

    Also, try putting the Sprite under the player & not the camera