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

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