I am doing minimap and with script it should show You-are-here point with current position the only problem is - the red point is always shown outside of the minimap region, although it is moving correctly. but it should be on the location of a minimap!
1 Answer
I've tried your blend file, but it's too heavy to work with. I've made an example file exclusively to answer your question. Download it here.
What you need to create a minimap is understand the concept of a viewport and make both minimap and game map the same size, so the dot position will work as expected.
How It Works
The basic concept of a minimap is:
- Create a Minimap scene, and the minimap object must be the same size as the game map. In this example, both have 200 meters on each side (delimited by the black borders).
- Add the Minimap as overlay scene.
- Set the viewport from Minimap scene's camera. Everything is detailed on the script
minimap.py
.
# Enable viewport use on map camera
camera.useViewport = True
# Pre process the viewport pixel coordinates
left = getWindowWidth() // 2
bottom = getWindowHeight() // 2
right = getWindowWidth()
top = getWindowHeight()
# Set viewport coordinates
camera.setViewport(left, bottom, right, top)
- Store the player's position and rotation on
globalDict
.
# Store player position and rotation on globalDict
globalDict['position'] = list(own.worldPosition)
globalDict['rotation'] = list(own.localOrientation.to_euler())
- Update the arrow representation from minimap based on values from globalDict.
# Check if values are present in globalDict
if 'position' in globalDict.keys() and 'rotation' in globalDict.keys():
# Update arrow's position and rotation
own.worldPosition = globalDict['position']
own.localOrientation = globalDict['rotation']
Additional Notes
Every object from Game scene is a group instance from scene _LibScenery.
The Minimap is added as overlay scene automatically at game start on object PlayerCollision from scene _LibScenery.
-
$\begingroup$ thank you. but how do i set the camera so high that to have the whole gameworld in aerial perspective like in your example? My gameworld is big and when i set the camera high, it stops showing anything on some altitude $\endgroup$ Commented Jul 26, 2019 at 21:05
-
1$\begingroup$ @ArtemKuzmin Simply increase the camera clipping distance (Properties editor > Camera tab > Set to Orthographic and Clipping End to to a high value). $\endgroup$ Commented Jul 27, 2019 at 13:13
-
$\begingroup$ thank you. i am doing something similar right now. could you probably help with this - blender.stackexchange.com/questions/146546/… $\endgroup$ Commented Jul 27, 2019 at 13:14
-
1$\begingroup$ @ArtemKuzmin Go to the scene _LibScenery and switch the layers to find the original player, the one on the game scene is just a group instance. $\endgroup$ Commented Aug 26, 2019 at 15:21
-
1$\begingroup$ hey man i mentioned you in my Acknowledgement section here for my thesis. thanks. drive.google.com/open?id=1ehDAAdBpWApNsSO-4U3joegglQrTq4uT $\endgroup$ Commented Jan 14, 2020 at 14:26
globalDict["Pos"]
(a list? If so, why dividing it?), etc. $\endgroup$