Hello Guest

Author Topic: "Grounding" sprite characters?  (Read 5155 times)

Majicpanda

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
"Grounding" sprite characters?
« on: December 30, 2013, 02:52:40 am »
I've got characters made up of a body (includes feet), head, equipped chest and head etc all stacked together by Z and I'm having trouble grounding the characters in my scene without the use of physics.

I've got a Final Fantasy style screen so I've created spawn points in the form of GameObjects on the level and then use the following code to position them:
Code: [Select]
Bounds bounds = baseSprite.GetUntrimmedBounds();
AdventurerSpawnLocation apl = dungeonInstance.adventurerSpawns.Find(spawn => spawn.partyPosition == a.partyPosition);
Vector3 pos = apl.transform.position;
pos.y += bounds.size.y / 2f;
a.transform.position = pos;

This works out pretty well, but I'm having problems using it in paper dolls in character screens and other areas where I'm resizing the baseSprite at run time to mimic new races like dwarves, giants etc... I have a base sprite that has the whole body and then change the scale to 1.1 1.1 1.0 for example on a Giant as well as all equipped items.

Is there any better way to do this? Perhaps re-do all my characters with a new pivot at their feet so I can simply set position to the spawn point if the spawn point is at the ground location I want?  The main issue is changing the baseSprite scale at run time and then maybe the bounds are not calculated correctly? Not sure why I'm getting results where the "feet" aren't at the same position.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: "Grounding" sprite characters?
« Reply #1 on: December 30, 2013, 11:36:57 am »
It depends on where the anchor is on the body, if its in the middle, then obviously its going to scale relative to that... You could add an attach point for the base of the feet, then position relative to that - you should be able to position things relative to the feet in addition to everything else then?

Majicpanda

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: "Grounding" sprite characters?
« Reply #2 on: December 31, 2013, 07:23:49 pm »
Assuming I went through the trouble of setting an anchor point at the feet of all my enemies in game would I simply then be able to do monster.transform.position = spawnPoint.position because it would position that anchor directly at the spawn point, automatically adjusting the feet to the "ground" spawn point?

I am already using the bounds of the sprite because I am dynamically setting hp bars under the sprites also, so I'm getting the bounds.min of the sprite (trimmed version) and offsetting by an amount .. that works great.  I also do this for putting a bouncing target arrow above the sprites when selected by getting the max of the bounds Y value.

Is there any way to just get the min Y bounds of the sprite in world position and set it somehow to the spawn point?  That would save all the workflow and put it in code because it wouldn't matter where the anchor was at that point.. I don't think.

Would look something like... get X min and max and divide by 2 to get the center of the sprite and then get Y bounds min value and somehow position that directly at the spawn point.

« Last Edit: December 31, 2013, 07:25:40 pm by Majicpanda »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: "Grounding" sprite characters?
« Reply #3 on: January 01, 2014, 11:46:40 pm »
renderer.bounds should give you the bounds in world space if your sprite is already instantiated... that might help.