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.
c# unity3d 2d game-physics
add a comment |
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.
c# unity3d 2d game-physics
add a comment |
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.
c# unity3d 2d game-physics
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.
c# unity3d 2d game-physics
c# unity3d 2d game-physics
edited Nov 9 at 2:45
asked Nov 8 at 7:45
user5234003
328
328
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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