Not able to make Wall Jump properly









up vote
0
down vote

favorite












I am trying to make my player jump from wall. I know I can do that by adding force in opposite direction. but my player is jumping weirdly and I tried to solve it by reading and watching tutorial but can't do it by myself. I think I need more professional and experienced mind to solve this.



I have 2 script one take care of wall jump and other script is responsible for movement and jump from ground and in this script i have applied if I pressed button longer player will jump higher.



This is the PlayerScript



public class PLayer : MonoBehaviour 


float input;
public float moveSpeed = 10;
bool jumpButtonPressed = false;

float startingMoveSpeed;
[Tooltip("move Speed when player jump")]
public float jumpMoveSpeedDecrementor = 3;
public float jumpForce = 10;
Rigidbody2D rgbd;
float groundCheckRadius = 0.1f;
[HideInInspector]
public bool grounded,wallJump;
bool isJumping;



// Use this for initialization
void Start ()

startingMoveSpeed = moveSpeed;
wallJump = false;

private void Update()

if (!jumpButtonPressed)

jumpButtonPressed = Input.GetKeyDown(KeyCode.Z);




// Update is called once per frame
void FixedUpdate ()

if (Input.GetKeyUp(KeyCode.Z))

isJumping = false;





}


This is the second script which take care of the wall jump.I have added physics material to the wall with 0.02f friction.



public class WallJump : MonoBehaviour 
PLayer player;
public float rayDistance;
public int speed = 20;
public int speedY=300;
public LayerMask playerLayer;
// Use this for initialization
void Start ()
player = GetComponent<PLayer>();


// Update is called once per frame
void Update ()
//ray should not collide with the self
Physics2D.queriesStartInColliders= false;
//ray cast
RaycastHit2D hit = Physics2D.Raycast(transform.position,Vector2.right*transform.localScale.x, rayDistance);
//if hit wall and jump
if (Input.GetKeyDown(KeyCode.Z ) && !player.grounded && hit.collider.tag=="wall")

player.wallJump = true;
Debug.Log("adding force");
//add force in -X and y direction
GetComponent<Rigidbody2D>().AddForce(new Vector2(speedY*hit.normal.x,speedY),ForceMode2D.Impulse);
// GetComponent<PLayer>().flipUsingScale();

else

player.wallJump = false;




private void OnDrawGizmos()

Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, transform.position+ Vector3.right * transform.localScale.x * rayDistance);





Thank you for reading and helping immature programmer like me.



Jump error










share|improve this question



























    up vote
    0
    down vote

    favorite












    I am trying to make my player jump from wall. I know I can do that by adding force in opposite direction. but my player is jumping weirdly and I tried to solve it by reading and watching tutorial but can't do it by myself. I think I need more professional and experienced mind to solve this.



    I have 2 script one take care of wall jump and other script is responsible for movement and jump from ground and in this script i have applied if I pressed button longer player will jump higher.



    This is the PlayerScript



    public class PLayer : MonoBehaviour 


    float input;
    public float moveSpeed = 10;
    bool jumpButtonPressed = false;

    float startingMoveSpeed;
    [Tooltip("move Speed when player jump")]
    public float jumpMoveSpeedDecrementor = 3;
    public float jumpForce = 10;
    Rigidbody2D rgbd;
    float groundCheckRadius = 0.1f;
    [HideInInspector]
    public bool grounded,wallJump;
    bool isJumping;



    // Use this for initialization
    void Start ()

    startingMoveSpeed = moveSpeed;
    wallJump = false;

    private void Update()

    if (!jumpButtonPressed)

    jumpButtonPressed = Input.GetKeyDown(KeyCode.Z);




    // Update is called once per frame
    void FixedUpdate ()

    if (Input.GetKeyUp(KeyCode.Z))

    isJumping = false;





    }


    This is the second script which take care of the wall jump.I have added physics material to the wall with 0.02f friction.



    public class WallJump : MonoBehaviour 
    PLayer player;
    public float rayDistance;
    public int speed = 20;
    public int speedY=300;
    public LayerMask playerLayer;
    // Use this for initialization
    void Start ()
    player = GetComponent<PLayer>();


    // Update is called once per frame
    void Update ()
    //ray should not collide with the self
    Physics2D.queriesStartInColliders= false;
    //ray cast
    RaycastHit2D hit = Physics2D.Raycast(transform.position,Vector2.right*transform.localScale.x, rayDistance);
    //if hit wall and jump
    if (Input.GetKeyDown(KeyCode.Z ) && !player.grounded && hit.collider.tag=="wall")

    player.wallJump = true;
    Debug.Log("adding force");
    //add force in -X and y direction
    GetComponent<Rigidbody2D>().AddForce(new Vector2(speedY*hit.normal.x,speedY),ForceMode2D.Impulse);
    // GetComponent<PLayer>().flipUsingScale();

    else

    player.wallJump = false;




    private void OnDrawGizmos()

    Gizmos.color = Color.green;
    Gizmos.DrawLine(transform.position, transform.position+ Vector3.right * transform.localScale.x * rayDistance);





    Thank you for reading and helping immature programmer like me.



    Jump error










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to make my player jump from wall. I know I can do that by adding force in opposite direction. but my player is jumping weirdly and I tried to solve it by reading and watching tutorial but can't do it by myself. I think I need more professional and experienced mind to solve this.



      I have 2 script one take care of wall jump and other script is responsible for movement and jump from ground and in this script i have applied if I pressed button longer player will jump higher.



      This is the PlayerScript



      public class PLayer : MonoBehaviour 


      float input;
      public float moveSpeed = 10;
      bool jumpButtonPressed = false;

      float startingMoveSpeed;
      [Tooltip("move Speed when player jump")]
      public float jumpMoveSpeedDecrementor = 3;
      public float jumpForce = 10;
      Rigidbody2D rgbd;
      float groundCheckRadius = 0.1f;
      [HideInInspector]
      public bool grounded,wallJump;
      bool isJumping;



      // Use this for initialization
      void Start ()

      startingMoveSpeed = moveSpeed;
      wallJump = false;

      private void Update()

      if (!jumpButtonPressed)

      jumpButtonPressed = Input.GetKeyDown(KeyCode.Z);




      // Update is called once per frame
      void FixedUpdate ()

      if (Input.GetKeyUp(KeyCode.Z))

      isJumping = false;





      }


      This is the second script which take care of the wall jump.I have added physics material to the wall with 0.02f friction.



      public class WallJump : MonoBehaviour 
      PLayer player;
      public float rayDistance;
      public int speed = 20;
      public int speedY=300;
      public LayerMask playerLayer;
      // Use this for initialization
      void Start ()
      player = GetComponent<PLayer>();


      // Update is called once per frame
      void Update ()
      //ray should not collide with the self
      Physics2D.queriesStartInColliders= false;
      //ray cast
      RaycastHit2D hit = Physics2D.Raycast(transform.position,Vector2.right*transform.localScale.x, rayDistance);
      //if hit wall and jump
      if (Input.GetKeyDown(KeyCode.Z ) && !player.grounded && hit.collider.tag=="wall")

      player.wallJump = true;
      Debug.Log("adding force");
      //add force in -X and y direction
      GetComponent<Rigidbody2D>().AddForce(new Vector2(speedY*hit.normal.x,speedY),ForceMode2D.Impulse);
      // GetComponent<PLayer>().flipUsingScale();

      else

      player.wallJump = false;




      private void OnDrawGizmos()

      Gizmos.color = Color.green;
      Gizmos.DrawLine(transform.position, transform.position+ Vector3.right * transform.localScale.x * rayDistance);





      Thank you for reading and helping immature programmer like me.



      Jump error










      share|improve this question















      I am trying to make my player jump from wall. I know I can do that by adding force in opposite direction. but my player is jumping weirdly and I tried to solve it by reading and watching tutorial but can't do it by myself. I think I need more professional and experienced mind to solve this.



      I have 2 script one take care of wall jump and other script is responsible for movement and jump from ground and in this script i have applied if I pressed button longer player will jump higher.



      This is the PlayerScript



      public class PLayer : MonoBehaviour 


      float input;
      public float moveSpeed = 10;
      bool jumpButtonPressed = false;

      float startingMoveSpeed;
      [Tooltip("move Speed when player jump")]
      public float jumpMoveSpeedDecrementor = 3;
      public float jumpForce = 10;
      Rigidbody2D rgbd;
      float groundCheckRadius = 0.1f;
      [HideInInspector]
      public bool grounded,wallJump;
      bool isJumping;



      // Use this for initialization
      void Start ()

      startingMoveSpeed = moveSpeed;
      wallJump = false;

      private void Update()

      if (!jumpButtonPressed)

      jumpButtonPressed = Input.GetKeyDown(KeyCode.Z);




      // Update is called once per frame
      void FixedUpdate ()

      if (Input.GetKeyUp(KeyCode.Z))

      isJumping = false;





      }


      This is the second script which take care of the wall jump.I have added physics material to the wall with 0.02f friction.



      public class WallJump : MonoBehaviour 
      PLayer player;
      public float rayDistance;
      public int speed = 20;
      public int speedY=300;
      public LayerMask playerLayer;
      // Use this for initialization
      void Start ()
      player = GetComponent<PLayer>();


      // Update is called once per frame
      void Update ()
      //ray should not collide with the self
      Physics2D.queriesStartInColliders= false;
      //ray cast
      RaycastHit2D hit = Physics2D.Raycast(transform.position,Vector2.right*transform.localScale.x, rayDistance);
      //if hit wall and jump
      if (Input.GetKeyDown(KeyCode.Z ) && !player.grounded && hit.collider.tag=="wall")

      player.wallJump = true;
      Debug.Log("adding force");
      //add force in -X and y direction
      GetComponent<Rigidbody2D>().AddForce(new Vector2(speedY*hit.normal.x,speedY),ForceMode2D.Impulse);
      // GetComponent<PLayer>().flipUsingScale();

      else

      player.wallJump = false;




      private void OnDrawGizmos()

      Gizmos.color = Color.green;
      Gizmos.DrawLine(transform.position, transform.position+ Vector3.right * transform.localScale.x * rayDistance);





      Thank you for reading and helping immature programmer like me.



      Jump error







      c# unity3d 2d game-physics






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 2:45

























      asked Nov 8 at 7:45









      user5234003

      328




      328



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203293%2fnot-able-to-make-wall-jump-properly%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203293%2fnot-able-to-make-wall-jump-properly%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Crossroads (UK TV series)

          ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế