[Game Maker] Some questions

Comments

  • @Jurgen how I'd approach iso-metric slope collision detection... /

    I'd just use
    collision_point( x, y, obj, prec, notme );
    function, and check in the direction I need to look for the collision and remember what my slope is, and hopefully you keep it simple by assuming or making all your slopes just triangles. If your slopes vary in angle, you will have to write a in-between script that adjusts for different slopes.

    I have not made an isometric game yet in GMS, but read a few articles and tuts on it in the past, and what I remember is that it is a good idea to convert with a script new properties for x, y, transformed. So you will always be using say ix, and iy scripts to reference the x, y in your iso world. Then it should be a simple case of using the lengthdir_x, and lengthdir_y vector components with

    if collision_point( ix+lengthdir_x(len, dir), iy+lengthdir_y(len, dir), oSlope, true, true) {
    	//MOVE_TO_CONTACT_SCRIPT
    }


    Basically, do normal slopes for 2d world, and then transform it with you iso coordinates.

    Otherwise you can ignore it or fake it, and just return a collision type from slopes, and move your objects Z axis and swop the sprite maybe. Hmm now that I think of it, it is not as simple as doing normal 2d collisions and transforming it.
  • @Bensonance, thanks man. I've been at it for a couple of days now, them slopes.
    @Boysano, great, thankyou. as soon as I've got slopes down, I'll post an example of some kind, maybe do a tutorial:)

  • edited
    Never used GameMaker before and so decided to download and install it to see what its about. During installation, it wants to download every DX SDK update since 2005!! Is this really necessary? Its not cheap downloading all that stuff in this country. Unity doesn't require any of this nonsense. I feel like just cancelling the download and uninstalling. Am I doing something wrong? Is ther a way to skip all this ?
  • @Vintar I'm pretty sure you are doing something wrong. I've been using GM for almost a decade now, and currently have 5 different versions installed and I've never had to download any DX SDK updates. Are you downloading direct from YoYo or using the Steam version?

  • Direct from yoyo. Well, its all finished downloading now, but man that must have been a few MBs...
  • is it possible for one of my sprites to detect where another sprite will be in future.(gamemaker)
  • @cooldudue are you talking about determining the position of an object at a future point in time, or what frame of animation a sprite will be on?
  • determining the position of an object in future
  • So the first thing is determining time.

    room_speed is the variable for how many frames there are in a second.

    speed is how many pixels an object will move in a frame.

    direction is the direction the object will move.

    so

    future_x = x + (room_speed*Number_of_seconds) * speed * cos(direction);
    future_y = y + (room_speed*Number_of_seconds) * speed * sin(direction);
  • edited
    how would i make a computer ai for ping pong. in difficulties
  • @karuji i typed that in what the is equal to but an error occured
  • What @karuji gave you is a formula that looks ahead of the current frame to get a position. "Number_of_seconds" is something you need to feed into the formula yourself to know how many seconds ahead you're looking. I haven't worked in gamemaker for a while now, but I think speed and direction are part of objects' attributes.

    When you say "an error occured" there is no way for anyone to help you if you don't share what the error is.

    @cooldude I think you need to google some of those yourself. Making an AI is not something that can be done without understanding what you're building and how you're building it. Making an AI means giving the controls to the computer. So what do you want the "player" to do? Be always at the exact position of the ball? Then it's as simple as paddle.y = ball.y on every frame.

    If you want it to move towards the ball, then you gotta work how fast you want it to move. So set a "AI_paddle_speed_max", and every frame "paddle.y += AI_paddle_speed_max" or "paddle.y -= AI_paddle_speed_max" depending on if the paddle is below or beneath the ball.

    Then if you want the paddle to move in spaces smaller than "AI_paddle_speed_max" because it's close to the ball, you work out the difference in position between the two objects (ball.y - paddle.y or some such) and use that value up to a maximum of AI_paddle_speed_max.

    Want the AI to have a reaction time so it's more realistic? Gotta write that yourself.

    Make it move randomly? Work out how to achieve a random chance of moving up, moving down, or move towards the paddle. Over time.

    there is no "simple way" to make an AI. What I've given you are ideas of where to start. You gotta go find some reference, I'm sure there are tutorials. GOOGLE.

    Noone can write your AI for you :)
  • Ok firstly I realized that there was an error with my formula.

    Future_x = x + (room_speed*Number_of_seconds) * speed * cos(degtorad(direction));
    Future_y = y + (room_speed*Number_of_seconds) * speed * sin(degtorad(direction));


    The direction in GM is in degrees, and trig functions expect their input to be in radians.

    Second, as @Tuism, pointed out Number_of_seconds is something that is needed to be provided by the programmer. This is why I initially mentioned room_speed being the number of frames to elapse in a second.

    @Cooldudue now you can keep asking question, and I'm quite likely to keep responding with answers. It normally only takes me a minute of two, so it's honestly no big deal to me to type this stuff out, but and this is a pretty big but. Me doing that isn't going to be that beneficial to you as a growing game developer.

    So here is a little secret: we all start out just following tutorials and being not sure what we are doing.

    So here is Tom Francis's videos

    I honestly cannot stress how beneficial it will be for you to work through all of these. Like all these questions will become pretty easy solutions to you if you just work through the videos and do what he is doing. Just remember: unless you are practising what is being shown in the videos you aren't going to gain the knowledge from it. And if you do any variations from the videos then you should post it here and let people try it out.

    And here is the first video for you to watch.

    Thanked by 1Tuism
  • oh okay i thought watching videos would be embarrassing
  • How exactly would watching videos be embarrassing? I've watched so many. And learned so much.
    Thanked by 1Boysano
  • @cooldudue nah nothing embarrassing about it :) I'm probably better than Tom with GM and I love watching his videos. They are a fantastic way to learn and do things :D

    Which reminds me: there is this really great John Cleese video that I've been meaning to hunt down!

    Later folks
    o7
  • @Tuism oh damn I was hoping to keep that really cool video all to myself ;)
  • Hey guys, I have no knowledge of coding for games...... Can u help me somehow?
  • Hey @mike16y unfortunately I can't you how to program on the internet. I can however tell you that GM comes with a great set of tutorials which you can work through and learn how to use the engine with.

    Also there is the Tom Francis videos which are really good for starting out with.

    And here is the first video to start off with


    If you work through the videos you should have a pretty good grounding in GM, and you can start trying your own project. And well be around to help you with any trouble and questions :)

  • Thanks man....
  • how do check 2 variables at ounce
  • hey @cooldude

    I think you'll be more efficient at finding answers if you learn to google for them, the forum is inevitably slower for simple stuff.

    For example, I put in "gamemaker how to check two variables at once", and got:
    https://www.google.co.za/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=gamemaker how to check two variables at once

    in sumamry, you use the "and" statement to join conditions.
    so like:
    if ((something = true) and (height = 2))
    {
    }
    Thanked by 1cooldudue
  • how do i change the origin point while playing
  • edited
    var surf = surface_create(sprite_get_width(sprite_index), sprite_get_height(sprite_index));
    surface_set_target(surf);
    draw_clear_alpha(0, 0);
    texture_set_interpolation(false);
    draw_sprite(sprite_index,0,Orig_X,Orig_Y);
    surface_reset_target();
    
    sprite_index = sprite_create_from_surface(surf, 0, 0, surface_get_width(surf), surface_get_height(surf), true, false, New_Orig_X, New_Orig_Y);
    surface_free(surf);


    Orig_x and Orig_Y are probably just going to be the x and y of your object.
    New_Orig_X and New_Orig_Y need to be set/calculated by you.

    This isn't a cost effective operation. And I'm not 100% sure about how it will impact RAM and vRAM. So you shouldn't be running this for lots of objects or in step events.

    ---

    Also I haven't actually tested the code, but it should work. And don't worry too much about the fluff in it: it's just for cleaning the surface because working in vRAM tends to be a bit weird.

    Oh and one caveat: any kind of sprite_create has an option for disabling background, it does this by sampling the bottom left pixel of the image.
  • I would actually try to stay away from changing origin points during runtime, it'll probably confuse your game more than its worth. Try to pick an origin point and stick to it, most of the time it's possible to not change origin points if you plan from the start.
  • edited
    Why would you go through all the hassle (and slowdown) of doing the surface to new sprite with different origin thing when you can just call sprite_set_offset(ind, xoff, yoff) and be done? I knew there had to be something like this, older versions of GM had editable sprite origins during runtime.

    The GM help notes that this function will change the origin for the sprite resource itself (not just this instance of a sprite) so if you want multiple versions of the sprite to have different origins at the same time, copy the original sprite like so:

    sprite_assign(spr_Custom, spr_Base);
    sprite_set_offset(spr_Custom, sprite_get_xoffset(spr_Base), sprite_get_yoffset(spr_Base));


    You can then change the x and y offsets to be whatever you want (the above example just copies the values from the sprite being copied).
  • heys guys i need your help again

    i am currently making a soccer game my problem is how do i pass the ball. i want the player to pass depending on hard he is kicking.
  • edited
    So, what you're asking is way bigger than an easily answerable question, or a question about code. It requires a bunch of different systems to interact with each other, and you have to solve those yourself as the one designing the game.

    Does the ball move with physics? Does the ball move with the player? If so, how is your player character controlling the ball? How are you "pointing"? What's the difference between a pass and a kick? How do you target the player you want to pass to? How do you determine how hard you kick? Do you shout at a microphone, the louder the harder? Do you click a button a bunch of times in a second and the more times you click the harder it is? Is it depending on the distance from you to the target?

    Game design is about thinking about every single aspect of a "thing" and breaking it down into bits that you can describe on a millisecond to millisecond level. We are creating worlds here - we need to know everything about it.

    If you can't understand how you want your world to be, noone can really help you with that.
  • heya

    i need help making my ball move. the ball must move in the direction of the mouse pointer and must move at the speed of how long the player holds the mouse left button. my current coding is DnD so pls if possible send an image
  • Check out the book Game maker: Apprentice. After that get Game maker: Companion.
    Or come visit us in Somerset West and we can show you. you should really do those demos and Tutorials...
  • I am busy with a Hyper Light Drifter inspired RPG/work in progress and I need some help.
    I set up an object (with no sprite), called obj_overlay.
    Here is the code for obj_overlay:

    CREATE EVENT:
    depth = y*-3000;

    DRAW EVENT:
    if collision_point(obj_player.x,obj_player.y,obj_box,false,false)&&obj_player.depth>obj_box.depth{
    draw_set_blend_mode(bm_add);
    draw_sprite(spr_player,0,obj_player.x,obj_player.y-obj_player.z);
    draw_set_blend_mode(bm_normal);
    }

    What works is:
    As soon as my player object enters the visual space of obj_box (obj_box overlaps my player object), obj_overlay draws the player sprite. This effect I need so that I can see my player object behind a wall for instance.

    What I need:
    The desired effect would be that the "overlay player-sprite" should exist always and be invisible at first. Only when obj_box overlaps my player object, then the "overlay player-sprite" becomes visible. It also has to only be visible for the "part" of the player object which is being overlapped.

    Any help regarding this would be awesome.
  • edited
    This is what is generally called an image-space effect. The easiest way to do this in GM is with surfaces.

    1. Create a surface the size of your screen.
    2. Create an object called Player_Occluder and set all the objects that you want to occlude the player and display this overlay effect to use it as their parent object.
    3. Every step, clear the surface to 0, 0, 0, 0 (red, green, blue, alpha - I'll use this notation for colours for the rest of the post).
    4. Draw all the Player_Occluders on the screen to the surface at the same locations they appear onscreen, but the goal here is to draw with 0, 0, 0, 1 (so that they're only drawing alpha onto the surface.
    5. Draw the player sprite to the surface at the same screen location it normally appears, except you're going to want to be drawing with whatever colour you want the overlay to be, let's say 1, 0, 0, 1 - you'll want to be drawing with your blend mode set to blend the source colour by destination alpha (dst_alpha in GM, I think) and the destination colour by 0.
    6. Finally, draw the surface over the entire screen with an additive blending mode to see the colour appear.

    I'm no longer up to speed with the GML required to pull this off, so I can't give you code off the top of my head, but if you follow that logic you should be fine :)

    P.S. I'm not sure what you're referencing a variable called obj_player.z in your sprite draw call there. That feels like all it's going to do is break stuff.

    P.P.S. There's a chance that the new GM shader stuff could do this much easier without a couple of the intermediary steps. I have no idea how that works though... I'd do this with a shader in every other system though.
  • edited
    I think there is a very simple cheat to do this with a 2nd sprite of low alpa with separate depth and opposite visibility...
    @Jurgen
    So if your player is behind trees you can press space to show the 2nd draw or even a separate object sprite to draw this above all things in game to find player object.

    This method is fast and not smooth on overlapping edges, so you need to think when to allow it, if you are using a 2nd low alpa draw of player sprite it should be ok in most instances even animations.

    Maybe say exactly what you want to achieve so we can give you simplest and best looking solution please.
  • edited
    Thanks @disklekcia and @Boysano.

    Here is a link to youtube of what I am looking for:
    youtube.com/watch?feature=player_detailpage&v=Z8SqFoTJM0w

    I tried @disleksia's solution, yet I ran into problems drawing my player sprite to a surface. When I draw the player sprite the surface multiplies the drawn sprite.
    Im' still working on it and if I find a great end-result, I shall also post it on MGSA.

    @Boysano, I know that the following might also work:
    In DRAW event of the separate depth sprite(object):

    d3d_set_fog(true,c_white,0,0);
    draw_sprite(spr_player,0,obj_player.x,obj_player.y-obj_player.z);//The reason why I put z here is that it shall enable this sprite to be drawn as it jumps.
    d3d_set_fog(false,c_black,0,0);

    Thanks again for the help.
  • Jurgen said:
    Thanks @disklekcia and @Boysano.

    Here is a link to youtube of what I am looking for:
    youtube.com/watch?feature=player_detailpage&v=Z8SqFoTJM0w

    I tried @disleksia's solution, yet I ran into problems drawing my player sprite to a surface. When I draw the player sprite the surface multiplies the drawn sprite.
    Im' still working on it and if I find a great end-result, I shall also post it on MGSA.

    @Boysano, I know that the following might also work:
    In DRAW event of the separate depth sprite(object):

    d3d_set_fog(true,c_white,0,0);
    draw_sprite(spr_player,0,obj_player.x,obj_player.y-obj_player.z);//The reason why I put z here is that it shall enable this sprite to be drawn as it jumps.
    d3d_set_fog(false,c_black,0,0);

    Thanks again for the help.
    Yeah d3d are fun to work with,
    but slow and not for all platforms. So I assume you only are planning windows or mac platforms then.
  • hey guys

    I am working with irrational numbers and I would like to know how i would workout the next number.
    Example root 2 = 1,41?. What is the number after that and after that.
  • There is no such thing. For every two irrational (or rational) numbers there's another that lies between them.

    What are you trying to do?
  • i am trying to make a shooter game where the shooter shoots numbers but it must be in the irrational order
  • There is no such thing. For every two irrational (or rational) numbers there's another that lies between them.

    What are you trying to do?
    I think you misunderstood. @cooldude was asking for the next digit in the result. That's totally doable, just google "calculating root 2 digit by digit" and get a ton of code :)
  • okay i this is going to sound bad i searched calculating root 2 digit by digit (that @dislekcia told me) and i looked on Wikipedia but when i started reading had no clue of what was happening. if possible can anyone sum up a formula for me.
  • cooldudue said:
    okay i this is going to sound bad i searched calculating root 2 digit by digit (that @dislekcia told me) and i looked on Wikipedia but when i started reading had no clue of what was happening. if possible can anyone sum up a formula for me.
    I don't think many people here understand the maths involved either... I mean, yes, I kinda get what Newton's method is all about, but we're talking the origins of calculus here.

    Try the Stack Overflow links that came up, they had multiple implementations of Python source to do something like this. It'll take a bit of effort, but it shouldn't be too hard to translate that into GML.
    Thanked by 1cooldudue
  • Ohhhhh, yeah I misunderstood.

    Well, in that case it sounds a lot easier to just store the root in a float/double somewhere, and just access the result digit by digit, rather than calculating the next digit? Depending on how accurate these actually have to be? I mean, it's totally cheating, but cheating is awesome. :P
  • what is a float/double?
  • cooldudue said:
    what is a float/double?
    A float / double will return a double :P (sorry, programmer humor)

    A float refers to a floating point number, they're ways to represent numbers that can have decimal values (as opposed to integers) and they tend to have a much larger value space. In GM every number is essentially a float, although they call them reals (after real numbers in mathematics) and they're represented internally in the double format. A double is a floating point number with twice as many bits dedicated to it, a float with double the precision.

    It's important to note that floats aren't irrational - they will always end because there's only so much space to store values in.
  • okay i am confused i am so post to use a float to work digit by digit but the number cannot be irrational.
  • cooldudue said:
    okay i am confused i am so post to use a float to work digit by digit but the number cannot be irrational.
    All the code in those Stack Overflow posts on calculating roots digit by digit are about doing exactly that: Overcoming the limitations in the float representation of numbers (that they have to stop eventually, so they can't be irrational - they just try to get as close as possible to the irrational number they're trying to be) your job is going to be implementing that code yourself so that it can work in your game.

    Perhaps this is biting off a bit too much if the idea of a float is this confusing? You're running into a problem that nobody here is going to be able to solve for you - the solution is available, but implementing it will take time and effort away from the work others are doing, it's not a simple "Oh, turn on X and it'll fix the problem" situation.
  • @Boysano,basically just for windows at the moment:)
    With regards to my previous post...

    I have an object pillar that serves as my wall, placed next to eachother and my player object. The view is RPG style top-down.
    Here is the relevant code:

    DRAW Event for object surface:
    (The depth of obj_surface is -10000)
    if surface_exists(global.surface){
    if (obj_player.depth > obj_pillar.depth){
    draw_set_blend_mode_ext(bm_add,bm_subtract);
    }
    draw_surface(global.surface,0,0);
    draw_set_blend_mode(bm_normal);
    }else{
    global.surface = surface_create(room_width,room_height);
    with obj_pillar{
    draw_self();
    }
    }
    STEP Event for obj_player:
    depth = y*-1;
    DRAW Event for obj_player:
    surface_set_target(global.surface);
    draw_clear_alpha(c_white,0);
    draw_self();
    surface_reset_target();

    In the obj_pillar CREATE Event I set it's depth to y*-1;

    The problem:
    Obj_player, when higher up on the screen than obj_pillar, has the "draw_set_blend_mode_ext(bm_add,bm_subtract);" activated and is slightly darker in colour overall. Moving behind obj_pillar works as obj_pillar shows obj_player through it. When obj_player moves lower than obj_pillar, the blend mode is normal again and it's colour is slightly lighter (as normal).
    How do I get obj_player to stay the same colour/brightness and have it blend with obj_pillar only when it is higher up on the screen than obj_pillar?

    Here is a link to my dropbox for the gmz file:
    https://dropbox.com/s/2sn062qoue2sgia/SurfaceTest.gmz?dl=0
  • Hey @Jurgen,

    One possible solution is to make sure that you object depths are set according to the object's y coordinate.

    depth = -y; //Or some constant -y

    So now your obj_player will appear behind all the obj_pillar objects regardless of where it is on the screen. But you would like to show what's behind obj_pillar in a different blend mode right.

    What you have to do now is set your spr_pillar's collision mask back to cover the entire image. This is so that you can register a collision whenever your player moves behind one of the pillars. Now comes the fun part, knowing the exact obj_pillar that your obj_player is colliding with, you can calculate what part of obj_player's sprite is overlapping with obj_pillar.

    So your Draw Event for obj_player can be blank, or just have draw_self() in there somewhere without blend modes.

    Then in obj_player's Draw End Event set the blend mode to draw_set_blend_mode_ext(bm_add,bm_subtract) and draw only the part you found overlapped with obj_pillar using draw_sprite_part().

    So what you're doing is:
    Draw Event
    1.)Draw obj_player
    2.) Draw obj_pillar
    Draw End Event
    3.) Draw part of obj_player that overlaps with obj_pillar in blend mode of choice.

    Here are some things you will likely need to solve along the way:
    1.) What happens when there is a collision with two obj_pillar objects.
    2.) Your collision code for obj_player against obj_pillar will now have to have a special check so that you can be behind it, but not walk down through it.

    The above will only work correctly if obj_pillar remains a perfect rectangle. If it's edges become irregular or there are see through holes in it, you'll have to look to surfaces or shaders to make it work correctly.
  • pieter said:
    depth = -y; //Or some constant -y
    That's happening already, see @Jurgen's code for "depth = y*-1" ;)

    @Jurgen: You're going to need to abandon this idea that you can just change the blend modes and have that magically do what you want. Your images are always going to look different when all you do is change their blend modes, that fundamentally alters the maths of how that sprite's colours are placed on the screen.

    What you want to do (and what @pieter outlines so well) is that you're going to need to come to terms with drawing the same sprite (your player) twice: Once as normal how you want it to appear when it's not overlapped by anything (at the correct depth), and a second time above everything else ONLY where it overlaps walls. Exactly how you do the calculation of what to draw for the second part is up to you and what you feel comfortable implementing, but just futzing with draw modes on their own is not going to get you where you want to go.
Sign In or Register to comment.