This code will make all instances of that object move down together. You can use the object if want to manipulate all instances at once, like this: "with(o_player) y++ ". The object will always return the same index of some instance, causing the problem reported, that the player instance always point to the same enemy instance (coincidentally, the first instance created) In the original code when calling the point_direction, was used the object enemy instead of the instance returned by instance_nearest function. The function will check all instances that was created from the informed object and will returns the index/reference of the instance nearest to the player. When the function "instance_nearest" is called it receives the player instance position (x and y) and the object of the instances that you want to check if it's near to the player, for example, the enemy object. If you only have one instance of that object, it will work referencing the object directly, but after more were created, it will return the index of only one of them (maybe the first created).Ībout instances: every object that you drag to the room will became an instance of that object or when you create an instance from the code, like calling "instance_create_layer(x, y, "instance_layer", obj_Bullet)", this function will return the reference/index of the new instance created. The object is the template that the created instance is based of, if you want to manipulate or get information you should reference the instance. But not sure if the reason of the problem was clear, then I want to complement by explain that the problem happened because the code in "point_direction" is referencing the object instead of the instance. In the Create Event of the oPlayer object, let's define a couple of new variables.I think the answer gave by YellowAfterlife solved the problem. The easiest way to do this (without changing out basic movement code) is to change our aSpeed variable according to whether we are in the air or on the ground. You can take away in-air control entirely or allow for precise in-air control. How to use google docs to create, edit, and collaborate on documents online. Source: Click share to share your spreadsheet and then choose what collaborators can do. Go to file > share > publish to web on the taskbar. Given our current setup, it's also really easy to adjust the amount of horizontal control the player has in the air. Anybody with a google account can use google docs at no cost. Try adjusting the value that ySpeed is multiplied by to see how this changes the feeling of the jump. If all of that checks out, then your ySpeed is divided in half. Next, we check to see if you are NOT holding the jump button (you just tapped it and let go). First, we check to see if onGround is false (you are in the air) and your ySpeed is less than zero (you are traveling up). When you let go of the jump button, your ySpeed is cut in half and your jump is cut short. Below the code we just added in the normal_state script, add the following lines.Ĭopy code Copied to clipboard. Tapping the jump button results in a short hop, while holding the button results in a full jump. This means that you jump higher the longer you hold the jump button. This may not be exactly what you want for your own game you may prefer to have a variable jump height. You may have noticed that jumping is always the same height, no matter how long you hold the jump button. This is our very scientific application of gravity. As long as our character is in the air, as indicated by onGround=false, we cause gravity to affect his vertical velocity by adding gSpeed to ySpeed. This is where our gSpeed, gravity speed, is being applied to the character. Before adjusting either of those values, though, open the code in the Begin Step event of the oPlayer object. These are all easy things to tweak by adjusting our gSpeed and jPower. Run the game and check out your new jump! How does it feel? Too slow? Too fast? Does your character jump too high? Or maybe not high enough? No problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |