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

3D Rotate sprite from centre, not from side (GMS2) [SOLVED]

Kiwi

Member
I'm playing around with 3d at the minute which is quite fun, I've learned how to use vertex buffers and formats to create walls, floors, etc.

I'd like my npc's to always face the player, but they seem to be rotating from the side rather from the middle for some reason.

I've made this npc spin around for example:

ezgif.com-optimize(1).gif

I tried to add an offset to the x position, but as I thought, it just shifts the object to the side while still retaining the same issue.


Here's what I have in my create event:
Code:
vertex_format_begin();

    vertex_format_add_position_3d();
    vertex_format_add_colour();
    vertex_format_add_texcoord();

fmt = vertex_format_end();

vb = vertex_create_buffer();

vertex_begin(vb, fmt);
    
    //tri 1 //////////////
    
    //BL
    vertex_position_3d(vb, 0, 0, 0);
    vertex_colour(vb, c_white, 1);
    vertex_texcoord(vb, 0, 1);
    
    //TL
    vertex_position_3d(vb, 0, 0, 16);
    vertex_colour(vb, c_white, 1);
    vertex_texcoord(vb, 0, 0);
    
    //BR
    vertex_position_3d(vb, 16, 0, 0);
    vertex_colour(vb, c_white, 1);
    vertex_texcoord(vb, 1, 1);
    
    //tri 2 //////////////
    
    //BR
    vertex_position_3d(vb, 16, 0, 0);
    vertex_colour(vb, c_white, 1);
    vertex_texcoord(vb, 1, 1);
    
    //TR
    vertex_position_3d(vb, 16, 0, 16);
    vertex_colour(vb, c_white, 1);
    vertex_texcoord(vb, 1, 0);
    
    //TL
    vertex_position_3d(vb, 0, 0, 16);
    vertex_colour(vb, c_white, 1);
    vertex_texcoord(vb, 0, 0);
    
vertex_end(vb);
And this is inside draw:
Code:
gpu_set_alphatestenable(true);

//var turn = point_direction(x, y, OBJ_mc.x, OBJ_mc.y)+90;
var mat = matrix_build(x, y, -3, 0, 0, turn, 1, 1, 1);
matrix_set(matrix_world, mat);

vertex_submit(vb, pr_trianglelist, sprite_get_texture(SPR_testnpc, 0));

matrix_set(matrix_world, matrix_build_identity());

gpu_set_alphatestenable(false);
 
Top