• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Increasing Vert Speed

M

Motivating

Guest
Hello all, I'm having an issue with piece of code. So pretty much I'm making a vertical scroller game in which the character dodges branches by moving the the right and left of a tree. I want to make it so after 10 branches are passed or spawned the vertical speed increases by + 1. I have images to explain my concept and the code I tried but isn't working. Any suggestions on how to get this to work?
 
Last edited by a moderator:

jazzzar

Member
That's fairly easy, you should store how many trees have passed in a variable, now define a new variable and call it vsp
Give that variable any initial value (the one that suits your game), you simply check for the tree variable, if it's >=10, you increment vsp by one, and in the step event just put vspeed=vsp;
Good luck
 
M

Motivating

Guest
Should I put it in a collision detection event? like an invisible box each time a branch hits for every 10 hits increase vsp?
 
M

Motivating

Guest
Sorry for my noobness. trying to learn. So I added vpr as my variable for a spawned branch and made the vert speed +1 on 2x spawned branches but doesn't seem to work. Any suggestions?

Code:
vpr = instance_create (250,-150,Left_Branch)
if vpr = +2
{
vspeed = +1
}
 
M

Motivating

Guest
Ok so I made a box called 'branchcount' and made an collision event for the left_branch. Is there an action in Game Maker that counts the number of collisions with the object? My thought was to increase vert speed based on the # of collisions with left_branch
 

Mazey

Member
Code:
//create player object
branches_seen = 0; //create variable in which we store the amount of branches passed

//step player object
var inst = collision_line( 0, y, room_width, y, obj_branch, false, false ); //draw a line from the left side of the screen to the right side of the screen, with the same y coordinate as the player. If you have separate branch objects for left and right you could make a parent that they share for example
if (inst != noone && is_undefined(inst.seen)) //if we found an instance & the variable "seen" does not exists inside the branch instance
{
    inst.seen = true; //set variable "seen" inside the branch instance to true to avoid the same branch being "seen"/detected twice -> refer to if statement
    branches_seen += 1; //we passed a branch, add 1
}

if (branches_seen == 10) //if we've seen 10 branches
{
    vspeed += 1; //add 1 to vspeed
    branches_seen = 0; //set branches_seen back to 0
}
Something along these lines? this is untested
 
Last edited:
M

Motivating

Guest
Can't get it to work ;/, here is what I'm doing so far in the thumbnails. I think I set it up correctly not sure
 
Last edited by a moderator:

Mazey

Member
You don't need to make a new line object, add my code inside your player object (that's what I meant with the comments), then you just need to change obj_branch in my code to parent_branches and:
1) Create new object called
parent_branches (just leave it as it is)
2) Open both Right Branch and Left Branch and set their parent to
parent_branches.

 
Top