Answer the question
In order to leave comments, you need to log in
How to make the player react to the platform only by jumping on top of it?
In the game, the jump is performed automatically when the player's colliders (Box Collider) and the platform (Edge Collider) come into contact, it is impossible to make the jump work only when touching the platform from above, and from below it simply flies and ignores it.
the code:
private void OnCollisionEnter2D(Collision2D other)
{
if (move == true)
{
if (other.gameObject.tag == "Platform")
{
rb.velocity = Vector2.zero;
rb.AddForce(transform.up * hightjump, ForceMode2D.Impulse);
GetComponent<SpriteRenderer>().sprite = stay;
GetComponent<AudioSource>().Play();
other.transform.tag = "DelPlatform";
}
}
Answer the question
In order to leave comments, you need to log in
I don't remember if all colliders are covered by Platfrom Effector2d, but try it. There will automatically be an entry from the bottom, just check the boxes if necessary and scripts are no longer needed for it
Add a test for the sign of the player's vertical velocity to the condition. If the player is flying down and is above the platform, then jump, otherwise do nothing
Create a collider from below.
1) when crossing the lower collider, change the platform properties to pass;
2) when crossing the upper collider, we make the platform dense (fall from above and jump from below).
You may have to make a collider from below the player so that it does not get stuck.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question