Radar

Demo: Crayta
Demo is remixable, search for “Radar”, you should see “Radar Showcase” in the “remix a game” if you wanna see how parts of demo work inside.

How to use

  • Install package “Radar”
  • Open templates in Library
  • Drag UserRadar template on User template
  • (optionally) Drag PlayerRadar template on Player template
  • (optionally) and/or place WorldRadar anywhere in the world
  • Add script RadarTarget on any entity you want to be displayed on radar
  • (optionally) adjust radar range in property “range” on RadarUtils script under Player

Configurations

  • range: both WorldRadar and PlayerRadar templates have script RadarUtils. If you want to change how far your radar is working, change the property “range” under Player or in the instance of WorldRadar, that you installed in the wolrd
  • pivot: WorldRadar have pivot point locator, which you can move if you want to change from which point world radar is calculating distance and angle to targets
  • location: RadarUI widget under Player supports several possible locations in “location” property: bottom-right (default), bottom-left, top-right, top-left and center. Select any of those to place widget where you want it to be. There is also possible value “full”, which is used for WorldRadar
  • usePlayerForward: on PlayerRadar this is to use player forward direction instead of camera direction to define which direction is radar zero angle

Colors

All colors (except black background for now) in widget are customizeable, just check Asset Properties of widget, there you would see:

Last two would be later possible to override separately for point.

Manual Tracking Control

By default tracking would be enabled for all players for any entity that has RadarTarget script, however you can disable this using property startTrackingOnInit.
Uncheck it in case if you want to start tracking manually (possibly for only selected players f.e)

You can manually enable/disable tracking of a particular target for a particular player using methods StartTrackingForPlayer and StopTrackingForPlayer on RadarTarget script. Those can be called from server or client side.

Limitations

  • radar ignores z coordinate completely at the moment, it is technically possible to calculate angle and distance within plane , where camera forward vector is located, but it is not done yet
  • radar works completely on client side, so if you somehow manipulate location of entities client-side, it might interfere with the Radar, since it relies completely on data on client. In most situations this should be ok though
  • when using PlayerRadar, by default it would try to use user camera to define where user is looking to calculate angle to object. This does not work reliably in certain situations due to the bug explained here: GetCameraLookAt sometimes gives equal values - Bug Reports - Crayta. For orbit camera package implements stable workaround , but if you use action camera, then until this bug is solved, you can try to reconfigure PlayerRadar script under Player template to use player GetForward method always (with usePlayerForward property) - this would look a bit strange, because stuff would be rotating based on how character is rotated and they change their rotation somewhat randomly. You can also not do anything - then in situation when method gave wrong data, script would fallback to GetForward (but all other time would continue to use camera method)
  • removing targets with StopTrackingForPlayer or on destroy costs at least O(n), because it goes over the whole list to remove target, so if you have a lot of targets - this might become a problem. Perfomance fix for this is possible, but not yet done

Under the hood

All main calculations are performed client-side within ClientOnTick. It goes over targets list, which is kept under User in UserRadar. Targets register themselves in UserRadar using GetWorld():GetLocalUser() from ClientInit (or if manual tracking control is used- based on calls to StartTrackingForPlayer and StopTrackingForPlayer)

1 Like