I asked this question in the CON thread but I thought it'd be worth making a new thread for extra visibility - is this possible via CON code? I'd like to use it for spawning blood, footstep sprites .etc on sloped surfaces, but I don't even know where to begin to figure out what angle the sprite would need to be set at or how to calculate it, if it's even possible.
serious replies only; just a 'man i'd like this too!' would just clutter the thread up, thanks.
Page 1 of 1
Figuring out the angle of a sector slope for spawning sloped sprites
#1 Posted 31 March 2021 - 12:16 AM
#2 Posted 31 March 2021 - 12:47 AM
I think you want something like this:
I use that in Duke Forces to calculate the angle of the slope to help set the landspeeder models pitch and roll when driving it on a slope.
Your problem is a little different, but I think you want to make the sloped sprite face angvar, and then manipulate its slope in the right proportion to the floors slope.
ifn sector[mysector].floorslope 0 { getsector[mysector].wallptr A getwall[A].point2 B getwall[A].x x getwall[A].y y getwall[B].x x2 getwall[B].y y2 subvarvar x x2 subvarvar y y2 getangle angvar x y }
I use that in Duke Forces to calculate the angle of the slope to help set the landspeeder models pitch and roll when driving it on a slope.
Your problem is a little different, but I think you want to make the sloped sprite face angvar, and then manipulate its slope in the right proportion to the floors slope.
#3 Posted 31 March 2021 - 01:13 AM
that's fantastic, and a lot simpler than I thought - thanks a lot Dan!
This post has been edited by Jblade: 31 March 2021 - 01:13 AM
#4 Posted 31 March 2021 - 01:22 AM
Jblade, on 31 March 2021 - 01:13 AM, said:
that's fantastic, and a lot simpler than I thought - thanks a lot Dan!
Cool, let me know how it turns out. I played around with sloped sprites briefly last year and couldn't quite get the hang of them. Do sprite slopes have the same amount of precision as floor slopes? That could be a problem if the sprites are less precise.
#5 Posted 31 March 2021 - 01:30 AM
IIRC they're a bit dodgy when it comes to clipping (for building actual stuff in a map) but for cosmetic stuff they're absolutely fine. Only problem now is to find out if the sprite slope value is actually exposed to CON lol
#6 Posted 31 March 2021 - 01:41 AM
Jblade, on 31 March 2021 - 01:30 AM, said:
Only problem now is to find out if the sprite slope value is actually exposed to CON lol
The slope of a sprite takes up the same position as X and Y offset, where Y offset is the multiple of 256 and X offset 0-255 is precision down to single number, i.e. offset 40, 4 would be 40 + 1024 = 1064.
#8 Posted 31 March 2021 - 02:40 AM
Aleks, on 31 March 2021 - 01:41 AM, said:
The slope of a sprite takes up the same position as X and Y offset, where Y offset is the multiple of 256 and X offset 0-255 is precision down to single number, i.e. offset 40, 4 would be 40 + 1024 = 1064.
That should be automated...
#9 Posted 31 March 2021 - 07:50 AM
Sloped sprites have exact same precision as sector sloping.
Only quirk is setting a cstat and then combining two bytes (x and y offset) to get 16bit precision for the sloping itself.
Even sectors have a specific bit for "slope on/off" despite having a sloping value of 0 so even that is similar.
I believe I added some functions for sloped sprites in the AMC .m32 file I did, syntax is similar to CON so feel free to poke there to see an example. I actually let you copy sloping value from a sector to sprite and the other way around iirc.
One important thing to take in to account with sprites is that "firstwall" is fixed, sprites will tilt only in one direction and angles will merely rotate this.
If you want footprints then you will need to create some ART duplicates that rotate this picnum for you a bit. with 4 directions it should be enough but it can still some times face a bit weirdly.
Only quirk is setting a cstat and then combining two bytes (x and y offset) to get 16bit precision for the sloping itself.
Even sectors have a specific bit for "slope on/off" despite having a sloping value of 0 so even that is similar.
I believe I added some functions for sloped sprites in the AMC .m32 file I did, syntax is similar to CON so feel free to poke there to see an example. I actually let you copy sloping value from a sector to sprite and the other way around iirc.
One important thing to take in to account with sprites is that "firstwall" is fixed, sprites will tilt only in one direction and angles will merely rotate this.
If you want footprints then you will need to create some ART duplicates that rotate this picnum for you a bit. with 4 directions it should be enough but it can still some times face a bit weirdly.
#10 Posted 23 May 2024 - 05:34 PM
I was seeking some way to do this recently and just find out:
1st apply the CSTAT_SPRITE_SLOPE to your actor:
Then, you'll have obtain the current sector's floorslope property and convert it to xoff/yoffset:
After that, setup your sprite
The bad thing is that your actor will always be facing the first wall (as mentioned before).
I don't know if this is the best way to do this but it's working fine for me.
BTW I guess that you'll also need to calculate the correct z (getflorzofslope), as a decal not fall, so you'll need to set the ground position for it.
1st apply the CSTAT_SPRITE_SLOPE to your actor:
define CSTAT_SPRITE_SLOPE 48
// inside actor code or EVENT_GAME geta[THISACTOR].cstat my_cstat or my_cstat CSTAT_SPRITE_SLOPE seta[THISACTOR].cstat my_cstat
Then, you'll have obtain the current sector's floorslope property and convert it to xoff/yoffset:
var my_xoffset 0 2 var my_yoffset 0 2 var my_angle 0 2 var my_wall_id 0 2 var my_wall_x1 0 2 var my_wall_x2 0 2 var my_wall_y1 0 2 var my_wall_y1 0 2 var my_floorslope 0 2 var my_point2 0 2 defstate set_sprite_floor_slope // get sector data geta[THISACTOR].sectnum my_sectnum gets[my_sectnum].floorslope my_floorslope ife my_floorslope 0 break gets[my_sectnum].wallptr my_wall_id // setup xoff/yoff with floorslope value set my_xoffset my_floorslope and my_xoffset 255 set my_yoffset my_floorslope shiftr my_yoffset 8 and my_yoffset 255 // get wall data getw[my_wall_id].x my_wall_x1 getw[my_wall_id].y my_wall_y1 getw[my_wall_id].point2 my_point2 getw[my_point2].x my_wall_x2 getw[my_point2].y my_wall_y2 sub my_wall_x1 my_wall_x2 sub my_wall_y1 my_wall_y2 // retrieve the desired angle getangle my_angle my_wall_x1 my_wall_y1 add my_angle 512 // Don't ask me why I'm doin' this // apply values seta[THISACTOR].xoffset my_xoffset seta[THISACTOR].yoffset my_yoffset seta[THISACTOR].angle my_angle ends
After that, setup your sprite
onevent EVENT_GAME { ifactor xpto { state set_sprite_floor_slope } } endevent
The bad thing is that your actor will always be facing the first wall (as mentioned before).
I don't know if this is the best way to do this but it's working fine for me.
BTW I guess that you'll also need to calculate the correct z (getflorzofslope), as a decal not fall, so you'll need to set the ground position for it.
#11 Posted 09 June 2024 - 11:28 AM
This worked out perfectly. Good job man.
I adapted this for ceiling decals as well and it worked great.
I adapted this for ceiling decals as well and it worked great.
This post has been edited by VGames: 09 June 2024 - 11:41 AM
Share this topic:
Page 1 of 1