Changing Sprite/Image_Index based on relation to camera (3d)

L

LeoWolf

Guest
Hello! This is kind of a weird question but anyway.. I used to use GameMaker Studio 1 a bit, thought I would try it again I am using 2.
I would figure this would consist of plotting a line between the camera and object, then figuring which way it faced, then depending upon that which sprite to use?
Kind of like this effect tbh.
I wanted to try a 2.5d look as I have always made 2d stuff. Anyway thank you!
 

Yal

šŸ§ *penguin noises*
GMC Elder
  1. Check angle_difference between the camera forward direction and the direction the object is facing.
  2. This gives you a value between -180 and 180, so add 180 to the result and use mod to get it into the range 0-359.
  3. Divide that result with the "angles per subimage" factor (360 / image_number)... or in other words, multiply by number of frames and divide by 360. Now you have a fractional image_index for the correct direction.
  4. Add 0.5 and then floor() the result (this makes the center of the interval correspond to an exact subimage and changes from one image to another happen at halfway points).
  5. Depending on what direction you feel is most natural to have the sprite start off with, you might want to add or subtract a factor to compensate for that; 0 = 0 means that facing forward (showing back towards the camera) should be the first subimage. If facing the camera feels more natural, you'd add image_number/2. (If you're unfamiliar with how angles work, each subsequent subimage should turn clockwise in equal increments)
  6. Draw that subimage.
 
Top