Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

I can't get the correct local character position

A topic by miksol created May 29, 2019 Views: 212 Replies: 8
Viewing posts 1 to 9
(1 edit)

How can i get correct local position of character?

my code for test:

    // Use this for initialization
    void Start () {   
          SuperTextMesh stm = GetComponent<SuperTextMesh>(); 
          string stringForSearch = "TEST!";
          stm.text = "Hello, World!! Hello, World!! Hello, " + stringForSearch + " World!! Hello, World!! Hello, World!!"
          int characterIndex1 = stm.hyphenedText.IndexOf(stringForSearch);
          int characterIndex2 = characterIndex1 + stringForSearch.Length -1;
          STMTextInfo ti1 =[characterIndex1];
          STMTextInfo ti2 =[characterIndex2];
          Debug.Log(ti1.character + " - " + ti2.character);
          Vector2 boxSize = new Vector3(ti2.BottomRightVert.x - ti1.BottomLeftVert.x, stm.size);
          Vector3 boxLocalPos = new Vector3(ti1.BottomLeftVert.y + boxSize.x / 2f, ti1.BottomLeftVert.y + boxSize.y/2f, 0);
          //create box for test pos
          GameObject testObj = new GameObject("TestPosition");
          testObj.AddComponent<BoxCollider>().size = boxSize;
          testObj.transform.localPosition = boxLocalPos;


In your code, "boxLocalPos" is using BottomRightVert.y instead of .x, is that it? Also, you might have to invert the positional Y value.

(2 edits)

Thank you, yes, sorry, position X is ok. About position Y, I tried to use transform.InverseTransformPoint, but the position has not changed. Simple invert the positional Y value I tried too

if invert the positional Y value

(1 edit)

Oh, I see that the correct position Y is obtained if only the anchor is set to Upper, if Middle or Lower then the wrong position is issued.

Developer (1 edit)

Right, it's in the known bugs section of the docs, I completely forgot about that. Is it possible to leave it set to Upper for now? I feel bad leaving in a bug like that, but this is already a workaround?

(1 edit)

I have a lot of text puzzles tasks in the my project where MiddleCenter is used, so I can’t redo everything, maybe tell me how it can temporarily be fixed?


Hmm... okay this might work, but you might be able to use a VertexMod script to grab the exact vertex position data. I have a VertexModSample script included, there should be a sample in there showing how to get a specific vertex from a character index. I'm reeeally hoping that positional data is correct, regardless of Anchor, since it should be a copy of the vertex data the mesh uses.

Thanks, Kai, I'll try it !

(1 edit)

Thank you! I figured out what  positional Y value offset ,
 it is in line number 2853  SuperTextMesh.ApplyOffsetDataToTextInfo () 
 anchorOffset.y = VerticalLimit> -rawBottomRightTextBounds.y? (-rawBottomRightTextBounds.y   rawTopLeftBounds.y - rawBottomRightBounds.y) * 0.5f: 0f;
 This happens if only VerticalLimit> -rawBottomRightTextBounds.y respectively.
 For my while I just add this offset, you will probably find it easier to figure out where you  better  need to fix it.