• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Jump on and through the object

Smenkare

Member
Hi, i want to be able to jump on the object which makes me "jump" and jump through it. The problem is that my collisions arent precise and my jump is always different because of number of steps which collision was detected. I was trying many ideas and i cant figure it out, using alarm to destroy object which makes me jump after one step doesnt work too. I'll show on the picture what i need. 112e1e12.jpg
And this is my collision event
Code:
if (oSpear.spearIn == true) && (sPlayer.vsp > 0)
    {
        var height  = y - other.y;
       
        if (height < 0)
            {
                sPlayer.vsp += - 85;
            }
       
       
    }{/CODE]
 

Yal

🍋 *lemon noises*
GMC Elder
The easiest way to detect one-way collisions I've found is to check whether you're currently not inside a one-way platform, but your speed would make you collide with one in the direction it's blocking. So for a jump-through platform like in your example, all of these must be true for you to "hit" it (instead of passing through)
  • Your vertical speed is > 0 (i.e. you're moving down)
  • You're currently not inside this platform
  • Moving down would make you be inside the platform
This works even if the collision mask is thick, too! (Some other approaches I've seen require the mask to be 1 pixel narrow, but it's easy to get tunneling bugs for stuff like bullets that way so I like avoiding it...)
 

Smenkare

Member
The easiest way to detect one-way collisions I've found is to check whether you're currently not inside a one-way platform, but your speed would make you collide with one in the direction it's blocking. So for a jump-through platform like in your example, all of these must be true for you to "hit" it (instead of passing through)
  • Your vertical speed is > 0 (i.e. you're moving down)
  • You're currently not inside this platform
  • Moving down would make you be inside the platform
This works even if the collision mask is thick, too! (Some other approaches I've seen require the mask to be 1 pixel narrow, but it's easy to get tunneling bugs for stuff like bullets that way so I like avoiding it...)

I wrote this
Code:
if instance_exists(oSpear) 
{
var height = sPlayer.y - oSpear.y;
        if(height < 0) 
        {
if(place_meeting(x,y+1,oSpear)) 
    {

if(vsp > 0) && (colided == false)
    {
        
        
            
with(oSpear)
        {
            if (spearIn) 
            
                { 
                
                    spearDest = true;
                    sPlayer.vsp += -85;
            
                    
                    }    
                    
                    
                }
        
            }
    }
        }    
}
its in the step event and the problem is that i dont know how to check if i am already in the collision with my object. Should i use place_meeting statement for this? Here i only check if i will be but how to check if i am already?
 

woods

Member
yal said..
  • Your vertical speed is > 0 (i.e. you're moving down)
  • You're currently not inside this platform
  • Moving down would make you be inside the platform

so it would look something like this..

obj_player step event
Code:
if (vsp > 0) //are we moving down?
{
   if (!place_meeting(x,y,obj_platform)) //are we not touching the platform
   {
      if (place_meeting(x,y+1,obj_platform)) //will we touch the platform
      {
       // do stuff
       vsp -= 85;   


      {
   }
}
 

Smenkare

Member
yal said..
  • Your vertical speed is > 0 (i.e. you're moving down)
  • You're currently not inside this platform
  • Moving down would make you be inside the platform

so it would look something like this..

obj_player step event
Code:
if (vsp > 0) //are we moving down?
{
   if (!place_meeting(x,y,obj_platform)) //are we not touching the platform
   {
      if (place_meeting(x,y+1,obj_platform)) //will we touch the platform
      {
       // do stuff
       vsp -= 85;  


      {
   }
}
it seems legit but it doesnt work as it should be.
 

Smenkare

Member
I changed values cause im making high res game and with higher speed it doesnt detect collisions. I think ill need some smaller object following my character to detect collisions cause when my head is in another object it detects collision.
 

Tyg

Member
If you would like me to show you how to use the physics system its really easy
you can make objects solid or not, and use gravity for jumping and impulse

If your speed is too high yes, when you advance the character it passes through, because the next collision detection is checked after the advancemnet, you could simply clamp the speed for min and max values

but if you use the physics system theres no need for all that, if the object is solid you simply dont pass through
 
Last edited:

Smenkare

Member
Instead of "+1", use "+ vspeed", and also add another "if (vspeed > 0)" check around the entire thing.
I did it... Still it doesn't work. I dont know if im stupid or this enginge cant make it with such big and fast objects or im making this wrong way. Im using object which follows the player cause i cant use player mask for this. If my speed is high it doesnt detect collision as it should, i jump higher or lower. See it at youtube link.


It would be great if someone helps me, im trying to learn but i feel that im really bad at programming, still i love games.

Code:
if instance_exists(oSpear) 
{

if(!place_meeting(x,y,oSpear))
    {
if(place_meeting(x,y+ sPlayer.vsp, oSpear)) && sPlayer.vsp > 0 
            {
        
        with(sPlayer)
            {
                vsp += -85;
            }


        
        
            }
        }
    }
 

GMWolf

aka fel666
Another to phrase the same thing is, "will the feet cross the edge I want to collide with".

So for example:
Code:
if ( bbox_bottom < platform.bbox_top ) && ( bbox_bottom + vspeed > platform.bbox_top ) {
  y += platform.bbox_top - bbox_bottom;
vspeed = 0;
}
Of course you also need to check your bbox_left or bbox_right falls within the platform's bbox.

I prefer this technique because of how simply phrased it is.
 

Smenkare

Member
Another to phrase the same thing is, "will the feet cross the edge I want to collide with".

So for example:
Code:
if ( bbox_bottom < platform.bbox_top ) && ( bbox_bottom + vspeed > platform.bbox_top ) {
  y += platform.bbox_top - bbox_bottom;
vspeed = 0;
}
Of course you also need to check your bbox_left or bbox_right falls within the platform's bbox.

I prefer this technique because of how simply phrased it is.
It works very well but when i have many instances of my spear only one works. Should i use here "with" or "other" expression to interact in this way with all instances of my spear?
 

GMWolf

aka fel666
It works very well but when i have many instances of my spear only one works. Should i use here "with" or "other" expression to interact in this way with all instances of my spear?
You need to find a way to loop over all the platform instances.

A with statement could work for example.
 

GMWolf

aka fel666
Im not sure that i understand what you mean, loop over all the platform instances?
use a loop (such as a for loop) to run the code against every instance of the platform object.
(instance_number and instance_find is one way to do this)

for example:
Code:
for (var i = 0; i < instance_number(objPlatform); i += 1)
{
   var platform = instance_find(objPlatform, i);
   //Add collision code here
}
if you have a lot of platform instances, you may want to find a faster way to loop over potential platforms,

Is making another object to detect collision with closest platform and then running jump code is bad idea?
This might be an issue if you have to collide with more than one platform at a time.
 
Top