• 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!

how do i make a working conveyor belt ?

C

crazybloodmonkey

Guest
so i'm making a 2d platform game and i want to use some conveyor belts but i kind of can't figure out how do to it. i looked around and everyone's solutions either make my player just stand there or only move right. so anyways hoping i can get an answer because i want the conveyor belts to move the player right ,left and maybe even up in down. so anyways my player is obj_player and the conveyor belt is obj_cbelt

anyways your help would be much appreciated
 

TheouAegis

Member
Get the id of the conveyor belt below the instance. If there was an id retrieved, add theconveyor's horizontalspeed to the instance's x and the conveyor's vertical speed to the instance's y.
 
C

crazybloodmonkey

Guest
Get the id of the conveyor belt below the instance. If there was an id retrieved, add theconveyor's horizontalspeed to the instance's x and the conveyor's vertical speed to the instance's y.
so this is my second game and i still don't really understand code yet so i don't really know exactly what you suggested i do
 
C

crazybloodmonkey

Guest
To start try this way:
Code:
if place_meeting(x,y+1,obj_cbelt) {x+=2}
What it does is move the player to the right when it is over obj_cbelt
okay so i put that in my player's step event but i just fell through it even though i have obj_belt set to solid so i made a collision event in obj_player with cbelt and put that code in and that made it solid but my player wasn't moving
 

3dgeminis

Member
The behavior of the obj_cbelt object should be equal to another solid object.
You should parent it to the object you use as a wall or floor (solid).
 

TheouAegis

Member
You don't want the conveyor code in the collision event. Unless you ad persistent gravity... If you are standing on the conveyor belt when it is set tonsolid, you aren't colliding with it, you are hovering over it.

Code:
var cb = instance_place(x,y+1,obj_cbelt);
if cb > 0
{
    x += cv.xspeed;
    y += cv.yspeed;
}
[\code]

If you give your conveyor belt 2 variables xspeed for horizontal conveyance and yspeed for vertical conveyance, then put this code in the player's step event, it should make the player move when stansing on a conveyor. If it doesn't, then either your collision code is wrong and causing the player to not be on the belt, or you have physics enabled.
 
C

crazybloodmonkey

Guest
alright so i guess i'll just show my code (i proabobly should have started this thread like this)
so in obj_ player
create event:
Code:
/// initialize varibales
grav = 0.3;//changed
hsp = 0;
vsp = 0;
jump = 6;
movespeed = 2; //changed

dir = 1

doublejump= 1;
health= 1;


if (global.checkpointR == room)
{
x= global.checkpointx;
y= global.checkpointy;
}
step event:
Code:
if(global.pause) exit;

key_right = keyboard_check (ord("D"));
key_left = -keyboard_check (ord("A"));
key_jump = keyboard_check_pressed(ord("W"))

        
         move = key_left + key_right;
hsp= move * movespeed;
if (vsp < 10) vsp+= grav;

if (place_meeting(x,y+1,obj_wall))
//double jumping//
if (place_meeting(x, y+1, obj_wall)) {

grounded = true; // Add grounded as a new boolean.

doublejump = 1;

}

if (key_jump) {

if (grounded) {

vsp = -jump;

grounded = false;

} else if (doublejump) {

vsp = -jump;

doublejump = 0;

}
}


if (place_meeting(x+hsp,y,obj_wall))
{
  while(!place_meeting(x+sign(hsp),y,obj_wall))
  {
  x +=sign(hsp);
   }
 hsp = 0;
}
x += hsp;
if (place_meeting(x,y+vsp,obj_wall))
{
 vsp = key_jump * -jump
 } 
if (place_meeting(x+hsp,y,obj_wall))
{
  while(!place_meeting(x+sign(hsp),y,obj_wall))
  {
  x +=sign(hsp);
   }
 hsp = 0;
}
x += hsp;
if (place_meeting(x,y+vsp,obj_wall))
{
  while(!place_meeting(x,y+sign(vsp),obj_wall))
  {
  y +=sign(vsp);
   }
 vsp = 0;
}
y +=vsp;
{
//wall jumping
   if (key_jump) && (place_meeting(x-1,y,obj_wall) && !place_meeting(x,y+1,obj_wall) && !key_right)
{
hsp = 2;//changed
vsp = -jump;
}
if (key_jump) && (place_meeting(x+1,y,obj_wall) && !place_meeting(x,y+1,obj_wall) && !key_left)
{
hsp = -2;//changed
vsp = -jump;
}
    


// facing dir will be set either -1 or 1
if keyboard_check(ord('D')) +(-keyboard_check(ord('A'))) !=0
{
dir = keyboard_check(ord('D')) +(-keyboard_check(ord('A')));
image_xscale = 1;
}

// horizontal collison
if (place_meeting(x+hsp,y,obj_wall))
{
 while(!place_meeting(x+sign(hsp),y,obj_wall))
 {
  x+= sign (hsp);
 }
 hsp=0;
}
x+=hsp;
// vertical collison
if (place_meeting(x,y+vsp,obj_wall))
{
 while(!place_meeting(x,y+sign(vsp),obj_wall))
 {
  y+= sign (vsp);
 }
 vsp=0;
}
y+=vsp;

}
// conveyor belt
if place_meeting(x,y+1,obj_cbelt) {x+=2}



okay hopefully that helps also in obj_wall i just have a collision event with a move free in it set to just 0 it works for obj_wall but for my conveyor belt i think that could be causing it to be solid but not move my character
 

TheouAegis

Member
Don't makeanythong solid. You already have working collision code for non-solids.

Don't use collision events for the same reason.

You have repetitive code... You even have x+=hsp 3 or 4 times in that code... Call x+=hsp and y+=vsp only once at the wnd of your code.

Make obj_wall a parent of obj_cbelt. That will make your wall collisions work for cbelt. Once you have normal collisions working for cbelt, that last line should work.
 
C

crazybloodmonkey

Guest
Don't makeanythong solid. You already have working collision code for non-solids.

Don't use collision events for the same reason.

You have repetitive code... You even have x+=hsp 3 or 4 times in that code... Call x+=hsp and y+=vsp only once at the wnd of your code.

Make obj_wall a parent of obj_cbelt. That will make your wall collisions work for cbelt. Once you have normal collisions working for cbelt, that last line should work.
alright so i did what you said i think i only put the horizontal collision and vertical collision in and applied it to the cbelt, that sort of work it moves me right but when i jump on in i was like going diagonally right anyways i edited the sprite and instead of floating the conveyor belts are just now slightly above the walls so you can't really see that diagonal motion if you jump on them so thanks it works but how would i go about making them push me left. like a i made another object the shows the conveyor belt going left but i'm not sure if i will have to use that
 

TheouAegis

Member
That's the same thing. Instead of adding two to the players X, subtract two or whatever.

Or you do what I said originally which is you use the conveyor belt's creation code to define what direction the conveyor belt is going and that way you only need one conveyor object.
 
C

crazybloodmonkey

Guest
That's the same thing. Instead of adding two to the players X, subtract two or whatever.

Or you do what I said originally which is you use the conveyor belt's creation code to define what direction the conveyor belt is going and that way you only need one conveyor object.
well i tried to mess with the creation code and i was able to flip it but it still goes right i did what i did to make it go right but i set it to negative 2 but it just kept going right
 

TheouAegis

Member
Do you prefer having two objects (left and right) or one object and setting its direction in the creation code (NOT the create event)?

If you ant two objects, remove ALL code from your left one and set its parent to the right one. Add a create event and set xspeed=-2. In the right object, add a create event and set xspeed=2.

Remind me, where is the code that is moving the player when he's on a conveyor?
 
C

crazybloodmonkey

Guest
Do you prefer having two objects (left and right) or one object and setting its direction in the creation code (NOT the create event)?

If you ant two objects, remove ALL code from your left one and set its parent to the right one. Add a create event and set xspeed=-2. In the right object, add a create event and set xspeed=2.

Remind me, where is the code that is moving the player when he's on a conveyor?
it's this in the obj_player step event( with the same horizontal and vertical collision i have to obj_wall)
// conveyor belt
if place_meeting(x,y+1,obj_cbelt) {x+=2}
 

TheouAegis

Member
So change that line to

with instance_place(x,y+1, obj_cbelt) { other.x += xspeed; }

Then as I said, in the Create Event for obj_cbelt put xspeed=2. Then if you want two distinct objects for left and right, put in the Create Event for the left conveyor xspeed=-2. Or if you choose to do the Creation Code method, any instance of obj_cbelt you want in the room to move left should have xspeed=-2 in its Creation Code.
 
C

crazybloodmonkey

Guest
So change that line to

with instance_place(x,y+1, obj_cbelt) { other.x += xspeed; }

Then as I said, in the Create Event for obj_cbelt put xspeed=2. Then if you want two distinct objects for left and right, put in the Create Event for the left conveyor xspeed=-2. Or if you choose to do the Creation Code method, any instance of obj_cbelt you want in the room to move left should have xspeed=-2 in its Creation Code.
ah finally it worked thanks for all your help
 
Top