Hello Guest

Author Topic: Need help with using Sprite ID's for hit detection  (Read 4357 times)

ivydevelopment

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Need help with using Sprite ID's for hit detection
« on: August 15, 2014, 10:43:13 pm »
Hello, I am trying to get my code to detect when I am walking in tall grass. I have a wildBattleEncounter script that should only run when the player is walking on the tall grass sprite. I've thought long and hard about it and I think the only way to do this would be to use the Sprite ID or Sprite Name. I've experimented with the Get tag and Get Name functions but it doesn't seem that TK2D uses Unity's built in tagging/naming system. Is there a function that I can call that will spit out the spriteID and/or name. Here is an example of the code I'm picturing in my head.

if(GameObject.FindGameObjectWithTags ("44")) {

wildBattleEncounter();

}

I apologize if what I am doing is completely wrong. I'm still trying to understand how 2D Toolkit does all of it's magic. I like the Quick n Simple tutorial series on youtube, but the videos they have are very limited and from what I've seen I never saw them use the sprite ID for anything.

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Need help with using Sprite ID's for hit detection
« Reply #1 on: August 16, 2014, 10:15:32 am »
Can you not create a prefab and name the objects via tags?

This is what I have done and works well when the object is available to the scene.  By coincidence I have just posted on the forum that I am unable to read the tag if its been instantiated and as such the layer collision matrix doesnt work and therefore unintentionally collides.

ivydevelopment

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need help with using Sprite ID's for hit detection
« Reply #2 on: August 17, 2014, 09:39:04 pm »
I don't think you can attach various tiles created using the 2D Toolkit. The more I use 2D Toolkit the more difficult it seems to be for my particular game. Every solution I run into is to just use built in Unity functions. I got 2D toolkit for it's tileset abilities, but it's proving to be more troublesome than it is worth.

The objects that I need to add special events too are tall grass, cave tiles, trees, water, ect. I got the toolkit so I wouldn't have to copy and paste large sections of prefabs to make my world. It is seeming as though that is what I'm going to have to do regardless :(

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Need help with using Sprite ID's for hit detection
« Reply #3 on: August 17, 2014, 11:17:17 pm »
You're using 2D Toolkit tilemaps? You should look into the API reference, there are loads of functions to help here. Eg. GetTileIdAtPosition and GetTileInfoForTileId. You really dont want to think in terms of tags and gameobjects here, they will be prohibitively expensive in a large map. The functions mentioned above are very very quick in comparison. Eg. you can simply sample the tilemap to work out if you're in tall grass or whatever.

ivydevelopment

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need help with using Sprite ID's for hit detection
« Reply #4 on: August 18, 2014, 12:12:01 am »
Yeah, thanks a lot. I just made a breakthrough. I'm figuring this stuff out. Thanks for the help.