Jump to content

How can I create a mini map in Leadwerks?


Yue
 Share

Recommended Posts

There's one if you look up "HUD Elements" in the Workshop that I got from Macklebee. You could probably chop that one up and make it work for you. The minimap script creates a bounding sphere around the player and looks for the KeyValue "enemy." So you have to add SetKeyValue to "enemy" in your target script. I think I included a crawler script that has that added in the Start function.

  • Upvote 1
Link to comment
Share on other sites

I was looking at the script, however I see commands called Buffer and strange things that are not documented.

My question is, using SetRenderTarget is equivalent to the same thing? At this point it is rendering what a camera sees in a texture or material.

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

 

Yeah the buffer is just a target to render to. All it's doing is double-buffering the scene. In the updateworld function you can see it's toggling between the two, and what occurs on the screen is bound to the buffer using Bind(). I think those were the important parts.

I messed with this CCTV script from here at one point http://leadwerks.wikidot.com/start   - which is kind of similar - but it never went anywhere. If I recall correctly the trouble I had was figuring out how to use the CCTV in the PostRender function.

  • Like 1
Link to comment
Share on other sites

image.thumb.png.c76a682d8cfe54fd1b604b30656da35c.png

 

My tests seem to fit what I need, but the drawback is that the camera that follows the character always has to look at the cube that renders the material with that texture so that it is updating the texture where the mini map is displayed.

Any suggestions?

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

15 minutes ago, havenphillip said:

That's cool. What script idea did you go with in the end?

What I did was to try to understand the system and create my own script, so I can learn a little bit about the subject.

This is only a prototype.

 

 

--##################################################
--# Proytecto 	: Astrocuco
--# Scripter  	: Yue Rexie.
--# Sitio Web	: https://www.iris3dgames.xyz
--# Fichero		: Hud.lua
--##################################################
--# Notas		: Script enganchado a la entidad
--#				  MiniMap. 
--################################################

Script.map = nil --entity "Map Mesh"
function Script:Start()

	self.entity:SetProjectionMode(Camera.Orthographic)
	
	self.texture = Texture:Create(256,256)
	
	
	self.mtl = Material:Create()
	self.mtl:SetShader("Shaders/Model/Diffuse.shader")
	self.mtl:SetTexture(self.texture)
	--self.mtl:SetColor(1,0,0)
	self.map:SetMaterial(self.mtl)

	self.entity:SetRenderTarget(self.texture)
	
	self.map:SetParent(World:GetCurrent():FindEntity("CameraPlayer"),true)
	self.map:SetPosition(-1,0,1,false)
	--self.entity:SetZoom(250)
	self.entity:SetFOV(45)
end



function Script:UpdateWorld()
	
	self.posPlayer = player:GetPosition(true)
	self.rotPlayer = World:GetCurrent():FindEntity("CameraPlayer"):GetRotation(true)

	self.entity:SetPosition(self.posPlayer.x, self.posPlayer.y+40, self.posPlayer.z, true)
	self.entity:SetRotation(90,self.rotPlayer.y,0,false)
end

function Script:PostRender(context)
	context:DrawImage(self.texture,0,context:GetHeight()-128,128,128 )
end

 

  • Like 2

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...