playMaker

Author Topic: Need help regarding distance to object calculation  (Read 585 times)

Evaldas

  • Playmaker Newbie
  • *
  • Posts: 21
Need help regarding distance to object calculation
« on: February 12, 2021, 05:05:56 AM »
Hello!

I wanted to ask for help setting a system, where the player would come close to certain objects and the name of those objects would pop up in 3D space (a very common thing in rpg/quest games).

I am able to do that by setting a sphere collider on the object, making a TextMesh pro layer, deactivating it and setting the trigger that when a player hits the collider it activates the Text layer.

It seems alright, but I’ll have quite a few objects with different names and I feel this is not the way to go. I’ve tried setting a global FSM with “get Distance” or similair actions, but I can’t wrap my head around how to calculate distance every frame to just certain objects and show the text only to those which are near the player. I thought maybe tags would help, but could not find a way how to convert tags to variables.

Also I've tried creating empty game object, adding a sphere trigger and parenting it  to the Player and making FSM on this trigger, but I don't understand why it does not work and the "on trigger enter" action does not activate when it collides with the object. I checked all the tags and objects multiple times. If I set up it the other way arround (having the trigger on the object) it works...

Maybe anyone would have any thoughts on this?
« Last Edit: February 12, 2021, 05:24:25 AM by Evaldas »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Need help regarding distance to object calculation
« Reply #1 on: February 12, 2021, 06:27:40 AM »
Hi.
I am just working on something similar.

but what i do is, on the player i use a box cast (can be any other type) every x frames (in my case every frame is not necessary so i use "NextFrameEventAdvance" (Ecosystem) and do it every 4 frames).
and look for enemy layer.

then send a event to that enemy to activate (in your case, show the name)
this way there is no trigger event needed for every enemy.

after enabling then the enemy gets the distance between player to disable when player gets further away.