Dimenticare

drawing NPCs in 3D

Dec 16th, 2016
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // drawing the NPC
  2. // it's basically just a transformed background
  3.  
  4. d3d_set_culling(false);
  5. var ca=camera_angle(id);
  6. d3d_transform_set_rotation_x(90);
  7. d3d_transform_add_translation(-16, 0, 0);
  8. // this is honestly very bad coding practice but it works
  9. d3d_transform_add_rotation_z(direction+90+90*(ca==CameraAngles.side));
  10. d3d_transform_add_translation(x, y, z+40);
  11. // this is like using sprite_index, except for a background
  12. draw_background_part(all_npc_images[image], (32*floor(frame)+32)%96, 48*ca, 32, 48, 0, 0);
  13. d3d_transform_set_identity();
  14. d3d_set_culling(true);
  15. // animation speed depends on how fast the NPC is moving
  16. frame=frame+point_distance(0, 0, xspeed, yspeed)/12;
  17.  
  18. /// CameraAngle camera_angle(object);
  19. // Returns a value representing the side of the object visible to the camera.
  20.  
  21. enum CameraAngles {
  22.     front,  //=0
  23.     side,   //=1
  24.     back,   //=2
  25. }
  26.  
  27. var angle=(((Camera.direction mod 360)-argument0.direction)+360) mod 360;
  28.  
  29. if (angle<=45||angle>315)
  30.     return CameraAngles.back;
  31. if (angle<=135)
  32.     return CameraAngles.side;
  33. if (angle<=225)
  34.     return CameraAngles.front;
  35.  
  36. return CameraAngles.side;
Advertisement
Add Comment
Please, Sign In to add comment