Are there problems with my OnJump solution?

I used a different solution to the OnJump challenge than in the video. Although my solution seems simpler (doesn’t need the capsule collider) and seems to work, I’m wondering if there are technical reasons why it’s not a good solution, or if it’s just different than the answer given. Thanks.

void OnJump(InputValue value)
int layer = LayerMask.GetMask(“Ground”);

            myRigidBody.velocity += new Vector2 (0f, jumpSpeed);
1 Like

Hi Smann,

Good job on developing your own solution. :slight_smile:

I do not see any reason why you should not do it this way. The only thing I would do is to move int layer = LayerMask.GetMask(“Ground”); to the instance level because a) you reuse the value over and over again, and b) we don’t know how performant GetMask is. Since calling GetMask once and storing the result in an instance variable is sufficient, you can simply do that and won’t have to figure out if GetMask affects the performance.

Is this what you wanted to know?

See also:


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms