• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

(GML) Tile collision using origin not working

So I was doing that Shaun Spalding tutorial on tile collision and I wrote the script exactly how he wrote, but it didnt work. It was a tile collision system based on origin points and my character had the same point as his. Here is the script I implemented to the step event
GML:
function PlayerCollision(){
    
    var _collision = false;
    
    
    //Horizontal
    
    if(tilemap_get_at_pixel(collisionMap, x + hSpeed, y))
    {
    
    x -= x mod 16;
    
    if(sign(hSpeed) == 1) x += 15;
    hSpeed = 0;
    _collision = true;
        
        
        
        
    }
    
    
    x += hSpeed;
    
    //Horizontal Entities
    
    
    
    
    
    // Vertical
        if(tilemap_get_at_pixel(collisionMap, x, y + vSpeed))
    {
    
    y -= y mod 16;
    
    if(sign(vSpeed) == 1) y += 15;
    vSpeed = 0;
    _collision = true;
        
        
        
        
    }
    
    
    y += vSpeed;
    
    return _collision;
    
    
}
the only thing is that I didnt use macros but I dont think that is an issue
 

PamiKA

Member
oh hey I have tried his tutorial before and I had some struggle getting it to work as well. I manage to resolve it but there was lot of things i had to go thru. Im curious of knowing whats going on from your side of the project.

I know I had to make sure the tile map size match and that the start up defines all tile set indexes correctly. Have you check that you using the right tilemap names?
 
Oh I forgot to say that the problem was that the collision was limited only to the pivot point and not to the rest of the sprite that was my problem.
 

TheouAegis

Member
Oh I forgot to say that the problem was that the collision was limited only to the pivot point and not to the rest of the sprite that was my problem.
Um, if you actually watch the full video, Shaun says that was the point of that code. If you don't want the collision to be based on the origin, then don't use that tutorial. It's... a really odd tutorial, to be honest. When I saw you say it was a Shaun tutorial for a tile collision around the origin, I honestly thought you had missed something. I actually watched the tutorial just now and then re-read the posts in this thread. You basically said it right here in the post I quoted: the code is working as intended. If you don't like the results, then go watch his other tile collision video (which has its own set of bugs) that uses the four corners of the bounding box.
 
Top