Jump to content


Photo

Sprite Direction depending on camera direction


  • Please log in to reply
5 replies to this topic

#1 millzyman

millzyman

    GMC Member

  • GMC Member
  • 560 posts
  • Version:Unknown

Posted 20 February 2012 - 09:39 PM

Hi.

I have sprites (or sets of sprites) that I plan on using in a 3D game. I have been trying to calculate a formula that will allow it to show the correct sub-image based on where the camera is looking and where the AI (or sprite) is looking.

e.g.

If the camera is looking at 180 Degrees and the AI is looking at 45 Degrees then the subimage shown would be 1

If the camera is looking at 0 Degrees and the AI is looking at 45 Degrees then the subimage shown would be 5

(The sprite starts at looking straight then goes anti-clockwise).

Basically if you imagine Doom that has the 2D enemy sprites, and they move in 8 directions - thats exactly the thing i am looking for, the image used is based on the ai's direction and the players *camera* direction (basically just the camera direction)

I can't really explain it more than that sorry, but hopefully i have explained it well enough that you might be able to put the pices of the puzzle together.

Edited by millzyman, 20 February 2012 - 09:40 PM.

  • 0

#2 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 20 February 2012 - 11:57 PM

Hi.

I have sprites (or sets of sprites) that I plan on using in a 3D game. I have been trying to calculate a formula that will allow it to show the correct sub-image based on where the camera is looking and where the AI (or sprite) is looking.

e.g.

If the camera is looking at 180 Degrees and the AI is looking at 45 Degrees then the subimage shown would be 1

If the camera is looking at 0 Degrees and the AI is looking at 45 Degrees then the subimage shown would be 5

(The sprite starts at looking straight then goes anti-clockwise).

Basically if you imagine Doom that has the 2D enemy sprites, and they move in 8 directions - thats exactly the thing i am looking for, the image used is based on the ai's direction and the players *camera* direction (basically just the camera direction)

I can't really explain it more than that sorry, but hopefully i have explained it well enough that you might be able to put the pices of the puzzle together.


subimage = round((point_direction(player.x, player.y, camera.x, camera.y)/360)*numOfSubimages)

  • 0

#3 millzyman

millzyman

    GMC Member

  • GMC Member
  • 560 posts
  • Version:Unknown

Posted 21 February 2012 - 12:28 AM

Yeah thanks that did work. I did get very close to that with my formula. But i still have one problem, here is my current code for the rotation of the sprite.

d3d_transform_set_identity()
d3d_transform_add_rotation_z(point_direction( x,y,obj_camera.x,obj_camera.y)) 
d3d_transform_set_rotation_x(90)
d3d_transform_add_translation(x,y,0) 
draw_sprite_ext(spr_peasent_stand,image_index,0,0,0.10,0.10,0,c_white,1)  
d3d_transform_set_identity() 


However it still doesn't work for the y axis (e.g. the sprite can't be seen when looking through the y axis (looking at 90 or 270 degrees). Any ideas as to whats causing the problem?
  • 0

#4 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 21 February 2012 - 01:49 AM

Yeah thanks that did work. I did get very close to that with my formula. But i still have one problem, here is my current code for the rotation of the sprite.

d3d_transform_set_identity()
d3d_transform_add_rotation_z(point_direction( x,y,obj_camera.x,obj_camera.y)) 
d3d_transform_set_rotation_x(90)
d3d_transform_add_translation(x,y,0) 
draw_sprite_ext(spr_peasent_stand,image_index,0,0,0.10,0.10,0,c_white,1)  
d3d_transform_set_identity() 


However it still doesn't work for the y axis (e.g. the sprite can't be seen when looking through the y axis (looking at 90 or 270 degrees). Any ideas as to whats causing the problem?

you might need to use floor/ceiling instead of round.
  • 0

#5 millzyman

millzyman

    GMC Member

  • GMC Member
  • 560 posts
  • Version:Unknown

Posted 21 February 2012 - 02:32 AM


Yeah thanks that did work. I did get very close to that with my formula. But i still have one problem, here is my current code for the rotation of the sprite.

d3d_transform_set_identity()
d3d_transform_add_rotation_z(point_direction( x,y,obj_camera.x,obj_camera.y)) 
d3d_transform_set_rotation_x(90)
d3d_transform_add_translation(x,y,0) 
draw_sprite_ext(spr_peasent_stand,image_index,0,0,0.10,0.10,0,c_white,1)  
d3d_transform_set_identity() 


However it still doesn't work for the y axis (e.g. the sprite can't be seen when looking through the y axis (looking at 90 or 270 degrees). Any ideas as to whats causing the problem?

you might need to use floor/ceiling instead of round.



There isn't any problem with the changing of sub-images. It is just the matter that the sprite doesn't turn with the player
  • 0

#6 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 21 February 2012 - 12:04 PM

What do you mean by "turn with the player"?

Edit:
use this instead
subimage = round(((point_direction(player.x, player.y, camera.x, camera.y)+player.direction)/360)*numOfSubimages)

Edited by hit172, 21 February 2012 - 12:06 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users