Comunidad Game Maker

Ayuda => Preguntas y respuestas => Mensaje iniciado por: J.E.A en Junio 06, 2011, 11:04:51 PM

Título: Problema al colisionar con esquina (Solucionado)
Publicado por: J.E.A en Junio 06, 2011, 11:04:51 PM
Hola a todos, tengo un peque?o problema con mi personaje y la pared.

Cuando colisiono en una punta del solido se queda pegado como 5 segundos, despues se despega

Les muestro en imagen el problema:
(http://i.imgur.com/DTFLA.png)
El problema esta donde marque con un circulo rojo, si colisiono asi de punta con mi personaje se pega. Y a veces me pasa con otras puntas tambien.
Aclaro que mi personaje tiene mask rectangular por lo que es un cuadrado perfecto

Dejo el adjunto por las dudas:

Título: Re: Problema al colisionar con esquina (Ayuda)
Publicado por: magnetox en Junio 08, 2011, 08:16:32 PM
Prueba usando una mascara circular en tu personaje. Si aun asi no funciona, postea aqui el codigo de movimiento y colision de los objetos para analizarlo detalladamente.

salu2 8)
Título: Re: Problema al colisionar con esquina (Ayuda)
Publicado por: J.E.A en Junio 12, 2011, 08:03:37 PM
Perdon por tardar en responder, tuve d?as un poco agitados.

Prob? con una mascara circular y tambi?n se pega en la punta. Les muestro el c?digo que tengo en el Step del personaje, en la colisi?n con el solido y los movimientos Left y Right

En Step:
[gml]if place_free(x,y+1) gravity=1

if not place_free(x,y+1) gravity=0
[/gml]

Ahora en la colisi?n con el solido:
[gml]if !place_free(x-hspeed,y) {move_contact_solid(direction,hspeed) ; hspeed=0}
if !place_free(x+hspeed,y) {move_contact_solid(direction,hspeed) ; hspeed=0}

if (vspeed>0 and !place_free(x,y+vspeed)) {move_contact_solid(270,abs(vspeed));vspeed=0}
if (vspeed<0 and !place_free(x,y+vspeed)) {move_contact_solid(90,abs(vspeed));vspeed=0}[/gml]


Tecla Left:
[gml]friction=0

if place_free(x-hspeed,y) {if hspeed>-vel_maxima {hspeed-=acel}}[/gml]

Tecla Right:
[gml]friction=0
if place_free(x+hspeed,y) {if hspeed<vel_maxima {hspeed+=acel}}[/gml]

Al soltar tecla Left:
[gml]friction=0.3

if place_free(x+hspeed,y) {if hspeed<vel_maxima {hspeed+=acel}}[/gml]

Al soltar tecla Right:
[gml]friction=0.3

if place_free(x+hspeed,y) {if hspeed<vel_maxima {hspeed+=acel}}[/gml]

Ojala puedan ayudarme  :)
Título: Re: Problema al colisionar con esquina (Ayuda)
Publicado por: Maniarts en Junio 13, 2011, 04:47:11 AM
te recomiendo usar este script, que ademas permite slopes y doble salto(editable)
[gml]/*
**  Usage:
**      motion(left,up,right);
**
**  Author:
**      Brian 'brod' Rodriguez
**
**  Arguments:
**      left        make object move to the left
**      up          make object move up (jump)
**      right       make object move to the right
*/

// NOTES
//////////

/*

** There are a number of variables that need to be
** called before you can use these scripts. They are
** found in objTest create event.

** Before you read, here are some notes about some of the
** functions I use.

**  Functions:
**      floor()     returns the number given without any decimals. (floor(1.34)=1)
**      ceil()      returns the number given without any decimals and 1# higher. (floor(1.34)=2)
**      sign()      returns the sign of the number. (Negative(-1)/Positive(+1)/None(0))
**      min()       returns the smallest number among the arguments. (min(1,3,103)=1/min(3,103,234)=3/min(103,234,834)=103)
**      max()       returns the largest number among the arguments. (max(103,234,834)=834/max(3,103,234)=234/max(1,3,103)=103)
**      abs()       returns the number's distance from 0. (It makes negative numbers positive, if they're not positive)

*/


// CONTROLS
/////////////

if (argument0 == true) //If the object is supposed to move right
{
   spr_dir    = 1; //Change the object's direction
   hsp        = min(max_speed, hsp + acc_speed); //Make the hsp increase by ACC_SPEED until MAX_SPEED has been reached
}

if (argument1 == true) //If the object is supposed to jump
{
   if (free == false) && (hold == false)
   //Make sure that they're on a floor (FREE=0) and that they haven't been holding the jump key (HOLD=0)
   {
       vsp  =-jmp_speed; //Jump!
       hold = true;      //The key has been pressed!
       jump = 1;         //The object has begun jumping
   } else if (free == true) && (hold == true) && (sign(vsp) == -1) {
       vsp-= grv_speed/2;
   }
   if (jump >= 1) && (hold == false) && (jump < max_jump) //Now, check if the object has already begun jumping(JUMP>=1),
   { //the object has pressed the jump key again (HOLD=0) and that the object hasn't reached the max amount of
     //extra jumps (JUMP<MAX_JUMP)
       vsp  =-jmp_speed; //Jump again!
       hold = true;      //Them key has been pressed!
       jump+= 1;         //Let the script know that the object has jumped again
   }
} else hold = false; //If jump key is not pressed, then that means it has been let go. So reset it.

if (argument2 == true) //If the object is supposed to move left
{
   spr_dir =-1; //Change the object's direction
   hsp     = max(-max_speed, hsp - acc_speed); //Make the hsp increase by ACC_SPEED until MAX_SPEED has been reached
}



// HORIZONTAL MOVEMENT
////////////////////////

repeat (ceil(abs(hsp)))
//This is to make sure, the code executes the code a POSITIVE(abs) amount of times, and also an INTEGER(floor / no decimals)
{
   var blk, mov;
   blk = place_meeting(x + sign(hsp), y, parSolid);
   //This checks, if there's a solid in the way of the object (1=Yes, 0=No)
   mov = false;
   if (blk == true) //There's a solid in the way! Now, to check if it's a slope
   {
       for (a = 1; a <= max_slp; a+=1)
       //Loop to find all possible heights, starting w/ the smallest gap (1px high) to largest gap ((max_slp)px high)
       {
           if (place_meeting(x + sign(hsp), y - a, parSolid) == false)
           //There is an empty space above it! So it IS a slope!
           {
               x  += sign(hsp); //Move forward!
               y  -= a;         //Move UP the slope
               mov = true;      //The object has moved!
               break;           //Stop checking for slopes, b/c the object just moved up one
           }
       }
       if (mov == false) //If the object HAS NOT moved..
       {
           hsp = 0; //That must mean there was no slope. So stop the object from moving
       }
   } else { //There's nothing stopping the object. So now the code will check if there's a downwards slope.
       for (a = max_slp; a >= 1; a-=1)
       //Loop to find all possible heights, starting w/ the lowest slope ((max_slp)px below) to highest slope (1px below)
       {
           if (place_meeting(x + sign(hsp), y + a, parSolid) == false)
           //There is an empty space below the solid! So it might be a slope!
           {
               if (place_meeting(x + sign(hsp), y + a + 1, parSolid) == true)
               //Now check that there's a solid below that empty pixel (or else you'll go down to an empty space)
               {
                   x  += sign(hsp); //Move Forward
                   y  += a;         //Move DOWN the slope
                   mov = true;      //The object has moved!
               }
           }
       }
       if (mov == false) //If the object has NOT moved
       {
           x+= sign(hsp); //Then that must mean there was no slope. So let the object go on it's way (b/c remember,
           //there was no solid soliding the path!)
       }
   }
}


// VERTICAL MOVEMENT
//////////////////////

repeat (ceil(abs(vsp)))
//This is to make sure, the code executes the code a POSITIVE(abs) amount of times, and also an INTEGER(floor / no decimals)
{
   if (place_meeting(x, y + sign(vsp), parSolid) == true) //If the object is above/below a solid
   {  
       vsp = 0; //Then stop the object from moving
   } else { //If the object is not on a solid..
       if (vsp != 0) //If the vsp is not 0
       {
           y+= sign(vsp); //Move!
       }
   }
}

free = !place_meeting(x, y + 1, parSolid); //Check if it's in air (true = in air, false = on ground)


// GRAVITY & FRICTION
///////////////////////

if (free == true) //The object is not on ground
{
   vsp+= grv_speed; //The object is falling, so make it fall!
   if (argument0 == false) && (argument2 == false) { hsp = max(0, abs(hsp) - air_frict)*sign(hsp); }
   //If the object is not moving, then slow the object down by the given AIR_FRICTion until it has stopped (0)
}

if (free == false) //The object is on ground
{
   jump = 0; //The object has stopped jumping.
   if (argument0 == false) && (argument2 == false) { hsp = max(0, abs(hsp) - gnd_frict)*sign(hsp); }
   //If the object is not moving, then slow the object down by the given GrouND_FRICTion until it has stopped (0)
}
[/gml]

En el objeto del personaje usa lo siguiente:

CREATE
[gml]image_index = floor(random(image_number));
image_speed = 0;

//////////////////////
// Object Variables //
//////////////////////

//Mandatory variables. Don't get rid of these!
hsp     = 0; //hspeed replacement
vsp     = 0; //vspeed replacement
jump    = 0; //Just a variable to check how many jumps you've made
free    = 1; //Whether you're in the air (1) or on the ground (0)
spr_dir = 1; //Sprite direction (useful for image_xscale)
hold    = 0; //Whether you're holding the left/right key

//Modify these to your heart's content.
grv_speed = 1;    //Speed at which vsp increases
air_frict = 0.15; //Number to decrease hsp by when no key is pressed in air
gnd_frict = 0.85; //Number to decrease hsp by when no key is pressed on ground
max_slp   = 2;    //Highest slope (in px)
max_speed = 4;    //Max speed to go by
acc_speed = 0.5;  //How much to increase the hsp by
jmp_speed = 6;    //How many pixels per step you jump by(decreases by grv_speed every step)
max_jump  = 2;    //Maximum amount of times you can jump before falling to ground(Starting from ground)[/gml]

STEP
[gml]motion(keyboard_check(vk_right) == true, keyboard_check(vk_up) == true, keyboard_check(vk_left) == true);

if (jump == max_jump) || (free == false) { max_jump = 2; } //Reset the max amount of jumps whenever you hit ground, or you're reached the max jump

//wrap in both direction when outside
[/gml]
PD: me funciona en 2D y 3D
Título: Re: Problema al colisionar con esquina (Ayuda)
Publicado por: J.E.A en Junio 13, 2011, 05:14:21 PM
Gracias Xivencorp, pero esta mal el c?digo parece, me da error en "motion"
Título: Re: Problema al colisionar con esquina (Ayuda)
Publicado por: Maniarts en Junio 30, 2011, 12:30:50 AM
Motion es el nombre del script, debes reemplazar esa palabra por la del nombre de tu script
Título: Re: Problema al colisionar con esquina (Ayuda)
Publicado por: J.E.A en Julio 14, 2011, 05:30:10 AM
Cita de: Maniarts en Junio 30, 2011, 12:30:50 AM
Motion es el nombre del script, debes reemplazar esa palabra por la del nombre de tu script

Mil disculpas por tardar decadas  :) :-[ Ya volv?, pruebo de esa forma y te digo como me fue
Título: Re: Problema al colisionar con esquina (Ayuda)
Publicado por: J.E.A en Julio 23, 2011, 12:37:27 AM
Como siempre, llego tarde, perdonen otra vez  :-[ Ahora se traba menos en las esquinas. Pero al ponerle una mascara circular no se traba.  :)
Gracias a todos  XD