This process is difficult to perform to allow the player to do a single jump. To make a player object do a single jump then you need to create two objects: the player and the solid object. The solid object is used for the player to stand on to jumped using both the gravity and gravity_direction code.
gravity- Current amount of gravity (pixels per step).
This code shown how many pixels of gravity the player object will be falling at a given number.
gravity_direction- Direction of gravity (270 is downwards).
This one is used to make the player fall down commonly with a given number 270.
vspeed- Vertical component of the speed.
This is used for making an object jumped in the jump button event. In order to make the player jumped upward then you need to set the number to a negative number. This can also be used to move objects upward or downward in movement events.
place_meeting(x,y,obj)- Returns whether the instance placed at position (x,y) meets obj. obj can be an object in which case the function returns true is some instance of that object is met. It can also be an instance id, the special word all meaning an instance of any object, or the special word other.
Lastly, this code is used for encountering an object for test variable purposes. The 'obj' can be used to set a certain object you want the player object to meet to perform a certain action. For this lesson, you'll want to use this code to make the player jumped if standing on a solid object.
Here is the code for making the player jumped:
Step Event:
if (!place_meeting(x, y+1, obj_solid))
{
gravity_direction=270
gravity=0.5
}
else
{
gravity_direction=270
gravity=0
}
Jump Key Event:
if (place_meeting(x, y+1, obj_solid))
{
vspeed=-12
}
gravity- Current amount of gravity (pixels per step).
This code shown how many pixels of gravity the player object will be falling at a given number.
gravity_direction- Direction of gravity (270 is downwards).
This one is used to make the player fall down commonly with a given number 270.
vspeed- Vertical component of the speed.
This is used for making an object jumped in the jump button event. In order to make the player jumped upward then you need to set the number to a negative number. This can also be used to move objects upward or downward in movement events.
place_meeting(x,y,obj)- Returns whether the instance placed at position (x,y) meets obj. obj can be an object in which case the function returns true is some instance of that object is met. It can also be an instance id, the special word all meaning an instance of any object, or the special word other.
Lastly, this code is used for encountering an object for test variable purposes. The 'obj' can be used to set a certain object you want the player object to meet to perform a certain action. For this lesson, you'll want to use this code to make the player jumped if standing on a solid object.
Here is the code for making the player jumped:
Step Event:
if (!place_meeting(x, y+1, obj_solid))
{
gravity_direction=270
gravity=0.5
}
else
{
gravity_direction=270
gravity=0
}
Jump Key Event:
if (place_meeting(x, y+1, obj_solid))
{
vspeed=-12
}