(Warning, I'm a noob) Problem with object movement (game maker 8.1)

M

mehmehmeh1

Guest
2 things:
1) When I set vertical speed to 0 (to prevent my character to fall off the screen after jumping), I can't move horizontally until I jump, any way to be able to fix this?
2) Is there any way to limit for how much time I can jump?
 
M

mehmehmeh1

Guest
I have some movment code for you, only if you wan't it, else if you don't im not much help unless you show me your code.

Heres the movement code:

In your player's create event do this:

Code:
grav = 1.50;
spd = 5;
jspd = 13;
hspd = 0;
vspd = 0;
fric = 1;
In your player's step event do this:

Code:
///Player Movment
 
//Ps. objBlox is your object that you collide with
 
var global.Dkey = keyboard_check(ord("D"));
var global.Akey = keyboard_check(ord("A"));
var global.Wkey = keyboard_check_pressed(ord("W"));
 
//Moving and Collisions
 
if(place_meeting(x,y+1,objBlox))
{
    vspd = 0;
        if(global.Wkey)
        {
            vspd = -jspd;
        }
}
    else
{
    if(vspd < 10)
    {
        vspd += grav;
    }
  
    if(keyboard_check_released(ord("W")) && vspd <-4)
    {
        vspd = -4;
    }
}
if(global.Dkey)
{
    hspd = spd;
}
if(global.Akey)
{
    hspd = -spd;
}
if(!global.Dkey && !global.Akey) || (global.Dkey && global.Akey)
{
    hspd = 0;
}
if(place_meeting(x+hspd,y,objBlox))
{
    while(!place_meeting(x+sign(hspd),y,objBlox))
    {
        x += sign(hspd);
    }
  
    hspd = 0;
}
x += hspd;
if(place_meeting(x,y+vspd,objBlox))
{
    while(!place_meeting(x,y+sign(vspd),objBlox))
    {
        y += sign(vspd);
    }
  
    vspd = 0;
}
y += vspd;
This should work... Please reply! : )
It gives me this:

___________________________________________
ERROR in
action number 1
of Step Event
for object ject1:

Error in code at line 11:
if(place_meeting(x,y+1,objBlox))
^
at position 25: Unknown variable objBlox
 

Yal

šŸ§ *penguin noises*
GMC Elder
1) When I set vertical speed to 0 (to prevent my character to fall off the screen after jumping), I can't move horizontally until I jump, any way to be able to fix this?
2) Is there any way to limit for how much time I can jump?
1: Move out of the block, you get stuck somehow. Do you change sprites between jumping and other states?
2: Use gravity? Only check for jumping when you're having a terrain block directly beneath you?
 
M

mehmehmeh1

Guest
I said in the code that objBlox is your object that the player runs into and stops.
So change objBlox into you solid block object.
OK, thanks, that's fixed now, but when I jump, my character only jumps like 3 pixels upwards then bounces down (and never stops)
 
Top