Character Jump

10 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€59.74
List Price:  €85.35
You save:  €25.60
£50.98
List Price:  £72.83
You save:  £21.85
CA$95.75
List Price:  CA$136.80
You save:  CA$41.04
A$107.05
List Price:  A$152.93
You save:  A$45.88
S$89.18
List Price:  S$127.41
You save:  S$38.22
HK$549.39
List Price:  HK$784.88
You save:  HK$235.49
CHF 56.03
List Price:  CHF 80.06
You save:  CHF 24.02
NOK kr704.56
List Price:  NOK kr1,006.56
You save:  NOK kr302
DKK kr445.69
List Price:  DKK kr636.73
You save:  DKK kr191.03
NZ$115.50
List Price:  NZ$165.01
You save:  NZ$49.51
د.إ257.04
List Price:  د.إ367.21
You save:  د.إ110.17
৳8,502.69
List Price:  ৳12,147.23
You save:  ৳3,644.53
₹5,998.21
List Price:  ₹8,569.24
You save:  ₹2,571.03
RM295.98
List Price:  RM422.85
You save:  RM126.87
₦108,101.65
List Price:  ₦154,437.55
You save:  ₦46,335.90
₨19,854.41
List Price:  ₨28,364.66
You save:  ₨8,510.25
฿2,271.74
List Price:  ฿3,245.48
You save:  ฿973.74
₺2,782.68
List Price:  ₺3,975.43
You save:  ₺1,192.74
B$388.94
List Price:  B$555.66
You save:  B$166.71
R1,236.78
List Price:  R1,766.91
You save:  R530.12
Лв116.78
List Price:  Лв166.84
You save:  Лв50.05
₩94,892.06
List Price:  ₩135,565.90
You save:  ₩40,673.83
₪237.58
List Price:  ₪339.41
You save:  ₪101.83
₱3,968.78
List Price:  ₱5,669.93
You save:  ₱1,701.15
¥10,092.94
List Price:  ¥14,419.11
You save:  ¥4,326.16
MX$1,319.50
List Price:  MX$1,885.08
You save:  MX$565.58
QR253.55
List Price:  QR362.23
You save:  QR108.68
P928.22
List Price:  P1,326.09
You save:  P397.86
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,492.25
List Price:  E£4,989.15
You save:  E£1,496.89
ብር9,546.71
List Price:  ብር13,638.75
You save:  ብር4,092.03
Kz63,827.73
List Price:  Kz91,186.38
You save:  Kz27,358.65
CLP$66,028.30
List Price:  CLP$94,330.18
You save:  CLP$28,301.88
CN¥501.86
List Price:  CN¥716.97
You save:  CN¥215.11
RD$4,114.15
List Price:  RD$5,877.61
You save:  RD$1,763.45
DA9,062.66
List Price:  DA12,947.21
You save:  DA3,884.55
FJ$156.79
List Price:  FJ$224
You save:  FJ$67.20
Q534.77
List Price:  Q763.99
You save:  Q229.22
GY$14,544.62
List Price:  GY$20,778.93
You save:  GY$6,234.30
ISK kr8,507.98
List Price:  ISK kr12,154.78
You save:  ISK kr3,646.80
DH634.96
List Price:  DH907.13
You save:  DH272.16
L1,184.67
List Price:  L1,692.46
You save:  L507.78
ден3,678.39
List Price:  ден5,255.07
You save:  ден1,576.68
MOP$562.12
List Price:  MOP$803.07
You save:  MOP$240.94
N$1,240.22
List Price:  N$1,771.82
You save:  N$531.60
C$2,558.21
List Price:  C$3,654.75
You save:  C$1,096.53
रु9,575.06
List Price:  रु13,679.24
You save:  रु4,104.18
S/250.07
List Price:  S/357.26
You save:  S/107.19
K288.18
List Price:  K411.70
You save:  K123.52
SAR262.49
List Price:  SAR375
You save:  SAR112.51
ZK1,630.29
List Price:  ZK2,329.08
You save:  ZK698.79
L302.90
List Price:  L432.74
You save:  L129.83
Kč1,479.59
List Price:  Kč2,113.79
You save:  Kč634.20
Ft23,867.60
List Price:  Ft34,098.03
You save:  Ft10,230.43
SEK kr661.64
List Price:  SEK kr945.24
You save:  SEK kr283.60
ARS$83,287.39
List Price:  ARS$118,987.09
You save:  ARS$35,699.69
Bs480.36
List Price:  Bs686.26
You save:  Bs205.90
COP$282,613.98
List Price:  COP$403,751.57
You save:  COP$121,137.58
₡35,156.33
List Price:  ₡50,225.48
You save:  ₡15,069.15
L1,816.10
List Price:  L2,594.55
You save:  L778.44
₲555,023.23
List Price:  ₲792,924.32
You save:  ₲237,901.08
$U2,814.67
List Price:  $U4,021.13
You save:  $U1,206.46
zł253.66
List Price:  zł362.39
You save:  zł108.72
Already have an account? Log In

Transcript

Can you do a game without a jump? Of course you can. But I think you should know how to make your character Jump. Jump is not a simple movement up and down right? It is a push off the ground, which has force and acceleration. And then the object goes down because of gravity now because we told him to do so.

Therefore, we work with physics here. Let's take a look at this Collider. We have created colliders for our sport, man and the ground, but we have a problem. When we are in a plane mode, you'll see that I was worried man doesn't stay on the ground. There, colliders cannot cross each other. So I decide to delete this collider and Create box one.

Okay, let's open our Sparkman go to capsule collider and remove component. All right. Now let's add another component box collider 2d. And it's Collider. It should be just the way our character is so that his legs can stay on the ground. Alright, maybe too big.

We have another collider for our sport man. And right now if we are on if we turn on that plane mode, we see that our player and take On the ground, but we still have this little little line. Because here's our ground Collider. Here's our character's collider and they cannot cross each other. How he can push off to jump. I'll tell you, let's go in our prefab and create a second collider like this, but it should be but it should have a part which is under our characters Collider.

And the next step is to select the second collider with that we have done and fine Is trigger and check it. Trigger colliders are used as triggers so they can and will cross other colliders. Alright, let's check it in the plane mode. So you see that our characters collider does not cross the grounds Collider, that the second collider is located inside the ground Collider. So yes, it does cross it. The next step is to add a tag to the ground so that we can define it by its tag.

Let's select our ground, find tag here and add tag And now we can simply select the tag ground from the list. All right time to code I use the same script goes for me jump is part of movement. First of all, let's create a variable which are going to help us with ground check. I remind you that serialized field makes a private variable visible from the inspector but it remains private. Okay, let's create a private variable type. Bull bull type means it can be true or false.

The name is is grounded and it is false. Next, we will use Another function that Unity has it is void and it is called on trigger. Enter 2d. This function is called when the collider others enters that trigger. We have a trigger on the second collider on our character remember alright so inside this function we check if there we check if other collider has a tag ground, by chance and if so is grounded true oh and we need to edit it we need to type other here all right. So again we take the other collider and check if this collider is tagged by ground and then the object is grounded and now vice versa.

We add a function, the private void the function on trigger exit to the again either here and I can simply copy it up and this time false on trigger exit to the is called When the collider other has stopped touching the trigger, all right, we have our checking. Let's go ahead inside the update function we already have our right left movement and let's add something or jump. I will use the curly brackets because you know it's a good a good practice to always use curly brackets because it doesn't understand that we have more than one line inside it. We cannot do it if we have only one line after that, but it is best practice. All right, so get component You can use this symbols if you'd like to add several conditions. So, in this case it means if this and this at once, first part here means if a user press that space button, that jump means space button.

Again you can check all this things inside the properties here. Again edit Project Settings input. So if a user presses space button and that variable is grounded, which we have declared, is true. And this second condition saves us from endless jumps. Our character jumps on If he is grounded the next part, and of course, where this is a direction of acceleration, and this is that instant impulse. You can change the number here and change acceleration that way.

Let's save it. Go back to unity and check it. Okay, but spacebar, yay, jumping. And if I want to if I press that pace while the character is in the air, nothing is happening because now Anthony jumps on the one jump from the ground, but of course, maybe you need endless Maybe so right now our sport man moves and jam, which is great, but he looks too boring without animation and it is waiting for you in the next lessons.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.