E
Eggyy
Guest
I'm currently working on a basic 3d dungeon crawler game, and I have a tree prop. I want it to be 2D, and it should always be able to face the player so it doesn't look terrible. How do i do this?
d3d_transform_add_rotation_x(90)
d3d_transform_add_rotation_y(0)
d3d_transform_add_rotation_z(cameradirection)
d3d_transform_add_translation(x,y,z)
draw_set_color(c_white)
draw_sprite_ext(my_sprite,image_index,0,0,0.5,0.5,0,image_blend,1)
d3d_transform_set_identity();
I managed to get it working with this code:There's a bunch of different solutions:
- Apply a transform before drawing a sprite with draw_sprite, such that its Y axis points in the direction that is "up" in 3D space and its Z axis points towards the camera. (This means you rotate it twice in succession). The old way of doing this is as such, but it's more efficient to do the same transform using a single transformation matrix:
Code:d3d_transform_add_rotation_x(90) d3d_transform_add_rotation_y(0) d3d_transform_add_rotation_z(cameradirection) d3d_transform_add_translation(x,y,z) draw_set_color(c_white) draw_sprite_ext(my_sprite,image_index,0,0,0.5,0.5,0,image_blend,1) d3d_transform_set_identity();
- Use the sprite as a texture for a d3d_wall that is drawn between two points offset with a step perpendicular to the camera's angle. This gives it the proper UVs to work with 3D lighting, which the sprite-rotation approach does not give.
View attachment 27019
/// Draw the wall
d3d_transform_add_rotation_x(90)
d3d_transform_add_rotation_y(0)
d3d_transform_add_rotation_z(o_player.dir + 90)
d3d_transform_add_translation(x,y,z)
draw_set_color(c_white)
draw_sprite_ext(s_tree_prop,image_index,0,0,0.5,0.5,0,image_blend,1)
d3d_transform_set_identity();
You can do that by using point_direction from the camera to the tree. I think you'll need to subtract 90 from that.the tree prop only rotates to where I look.... I'm wanting it to rotate... to face the o_player.
Because of the way the depth buffer works.Why are the transparent sections of my tree texture replaced by the background colour?