#How can I make a little UI that shows a side view

3 messages · Page 1 of 1 (latest)

vocal raptor
#

here's my implementation of that:

  1. create a new viewport node and name it "minimap". set its size to the desired size of your minimap.
  2. add a Camera2D node as a child of the minimap node.
  3. add a sprite node as a child of the minimap node.
  4. in the _ready() function of your player script, get the minimap viewport and set its render target to a new image texture.
  5. update the sprite's texture in the _process() function to the image texture of the minimap viewport.

node tree might look like this:

- spatial (root)
  - player
    - camera
    - script (player.gd)
  - minimap (viewport)
    - camera2d
    - sprite
#

to make the minimap follow the player, you can update the position of the minimap's camera node to match the position of the player in the game world. here's an example of how you might do this in your player script:

extends kinematicbody

var minimap_viewport = null
var minimap_camera = null

func _ready():
  minimap_viewport = get_node("/root/spatial/minimap")
  minimap_camera = get_node("/root/spatial/minimap/camera2d")
  minimap_viewport.render_target_v_flip = true
  minimap_viewport.render_target_update_mode = viewport.update_once
  get_node("/root/spatial/minimap/sprite").texture = minimap_viewport.get_texture()

func _process(delta):
  get_node("/root/spatial/minimap/sprite").texture = minimap_viewport.get_texture()
  minimap_camera.position = position
reef crypt
#

thanks