Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ZackMan12 · Oct 13, 2017 at 03:42 AM · positionupdategameobjectsminimapother

Create blips relative to the players position on a minimap.

I have a circular minimap in a canvas in my scene, and I have the blip on the player to follow it at every update. I am having trouble trying to get other blips on other targets to update relative to the players position. Here are the scripts I have. The first one is for the minimap to target the player. It also tracks any other blips position so if the object is offscreen, it is positioned on the edge of the minimap, depending where its position is to the player until its on screen. and the second one is tracking the blip on the UI on the minimap to update it. Any help would be appreciated!

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Minimap : MonoBehaviour {

 public Transform target;
 public float zoomLevel = 10f;
 Vector2 xRotation = Vector2.right;
 Vector2 yRotation = Vector2.up;
 public Vector2 TransformPosition(Vector3 position)
 {
     Vector3 offset = position - target.position;
     Vector2 newPosition = new Vector2(offset.x, offset.z);
     newPosition += offset.x * xRotation;
     newPosition += offset.z * yRotation;
     newPosition *= zoomLevel;
     return newPosition;
 }

 public Vector2 InsideMinimap(Vector2 blip)
 {
     Rect circleMap = GetComponent<RectTransform>().rect;
     float radius = Mathf.Min(circleMap.width / 2, circleMap.height / 2);

     if (blip.magnitude > radius)
     {
         blip = blip.normalized * radius;
     }
     return blip;
 }

 void LateUpdate()
 {
     xRotation = new Vector2(target.right.x, -target.right.z);
     yRotation = new Vector2(-target.forward.x, target.forward.z);
 }

}

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Blips : MonoBehaviour {

 public Transform target;
 Minimap map;
 RectTransform myRectTransform;
 public bool keepInBounds = true;
 public bool scaleLock = false;

 void Start()
 {
     map = GetComponentInParent<Minimap>();
     myRectTransform = GetComponent<RectTransform>();
 }

 void Update()
 {
     Vector2 newPosition = map.TransformPosition(target.position);

     if (keepInBounds)
     {
         newPosition = map.InsideMinimap(newPosition);
     }

     if (!scaleLock)
     {
         myRectTransform.localScale = new Vector3(map.zoomLevel, map.zoomLevel, 1);
     }
     myRectTransform.localPosition = newPosition;
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MaxGuernseyIII · Oct 13, 2017 at 03:47 AM

I liked they way they suggested to do it in their live event on mini maps...

https://unity3d.com/learn/tutorials/topics/graphics/adding-minimap-icons

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

82 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Transform position not changing. 2 Answers

Camera rotation around player while following. 6 Answers

How to create a dynamic map in hand of FPS like Far Cry 2 or Firewatch? 0 Answers

Using a number array? 1 Answer

Copy position into var without updating every frame 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges