Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

[SOLVED] "zscale" Variable Seemingly Affecting z-Axis Position, but not "z" Variable

A topic by WideWorldGames created Apr 01, 2024 Views: 131 Replies: 4
Viewing posts 1 to 3
(5 edits)

When creating my model (the exact tree sprite that comes with the demo), I notice that zscale is affecting the position of the object by making the base z position appear higher than its actual z position (double checked using debug messages upon creation). That is to say, if an object's z value is 64, and zscale is 1, the object will appear on the z-axis correctly, at 64. But if the object's z value is 64 and zscale is 2, the object will appear on the z-axis somewhere closer to 96 or so. I also notice that this gap is larger when the z value is larger, but only if zscale is above 1.

(edit: tested with zscale values below 1, and I can confirm that the objects' z positions appear lower than they're intended to.)

Create event: 

//var scl = (random number between 1 and 2)

//var z = (dependent on position, but often between 0 and 128)

// Create model

var model = fauxton_model_create(sprite_index, x, y, z, 0, 0, image_angle, scl, scl, scl);

fauxton_model_add_static(model, "PropBuffer");

// Cleanup

fauxton_model_destroy(model);

instance_destroy();

Any help is appreciated!

oh good catch! Yeah, fauxton is quite a bit out of date. I probably did some wrong math when trying to account for offsetting the VB planes or something. My suggestion would be to check into the fauxton internal functions. I need to sit down soon and refactor fauxton since when I wrote it originally I was quite trash at coding. Haha.

(+1)

Found it! I changed one specific _zs value within " __FauxtonWriteStaticSpriteStack" to 1 (bolded and commented below):

// Create and write to buffer (much faster than writing a direct vertex buffer)

for ( var i=0; i<_num * _zs; i+=1/_zs )

{

var _ind = ceil(i / _zs);

//if ( _ind > _num-1.6 ){ _ind = ceil(_ind); }

_ind = clamp(_ind, 0, _num-1);

__FauxtonWriteQuad(_buffer, sprite, _ind, _x, _y, _z + i + _zoffset, _col, _alp, _ang, _xs, _ys, 1)  //changed _zs to 1 here.

}

Hope this helps anyone facing a similar issue!

Oh nice! I figured it was something dumb that I did. haha. Great work! 

Doing a bit of a deeper dive, it seems like it only happens with the static buffer models, and not the original models. Going to check out some of those functions, and if I can't find a fix I'll see if my game can handle leaving the models in without creating static buffers (although I'd imagine this would cause a bit of a performance hitch down the line with large rooms)