Hello Guest

Author Topic: Need help with animations  (Read 5777 times)

ivydevelopment

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Need help with animations
« on: August 13, 2014, 12:22:39 am »
Hello. I'm making a 2D game very similar to Pokemon. I need to be able to drag and click large amounts of textures at once. I can do this using the default tilemap, but I want to be able to mass click animated tiles. I'm currently attempting to animate all the water. I don't see any easy way of doing this aside from making single animated sprites and copy and pasting several times.

I'm assuming there is a easy way of accomplishing this?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Need help with animations
« Reply #1 on: August 13, 2014, 11:25:30 am »
There isn't, sorry. Updating meshes in Unity is very slow and doing this can be prohibitively expensive. The best solution to this is to use a separate material / shader for the water. You can override the materials in the sprite collection.

ivydevelopment

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need help with animations
« Reply #2 on: August 15, 2014, 07:54:42 pm »
Okay, thank you very much for taking the time to help me. I appear to have run into another issue. I'm trying to setup collisions with objects like trees. I've followed various tutorials online, and read the official documentation on this site, but I'm not getting the results I'd like. I can get the collusion to work if a object falls from the sky and hits a tree,  but in a scene that is very much like the Pokemon world I walk into a tree and it bounces me up into infinity and if I attempt to walk into the tree enough times I'll eventually walk right through it and my character will start spinning. I've locked the X,Y,Z positions within the 3D rigid-body and that seemed to fix the rotation, but my character still moves up endlessly. It acts as though I'm playing pong :P

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Need help with animations
« Reply #3 on: August 16, 2014, 12:07:10 pm »
How are you moving your character? There are so many ways to do this in Unity that it probably is impossible to guess what you're doing and why this is happening ...

ivydevelopment

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need help with animations
« Reply #4 on: August 16, 2014, 09:59:04 pm »
How are you moving your character? There are so many ways to do this in Unity that it probably is impossible to guess what you're doing and why this is happening ...

I'm not able to use Ray Casts or any tagging systems to help me with my normal script so I'm using a script very similar to this. (At least from what I'm seeing so far).

if(Input.getkeydown ("s")) {

transform.position = new vector3 (transform.position.x,transform.position.y+1,transform.position);

}

Within Unity itself I would throw tags onto my collision objects with a bool to see if the player can move through it or not using ray casts. With 2D Toolkit I'm a bit lost because I don't seem to be able to tag items.  What I want to do, and I don't know if I can do it with 2D toolkit or not is this.

if(Input.GetKeyDown ("s")) {

 if (Physics.Raycast (transform.position, dwn, hit, Reach) && hit.gameObject.tag == "Passable") {

transform.translate (Vector3.down, 0);

}

}

I know the example code I wrote isn't complete, but I think it should give you an idea of what I'm doing, and more importantly what I'm doing wrong. Thanks for taking the time to help me :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Need help with animations
« Reply #5 on: August 17, 2014, 11:10:56 pm »
2D Toolkit tilemaps don't have tags, because they aren't individual objects. Having lots of individual objects in unity will drag down runtime performance (32x32 tilemap = 1024 objects..., and tk2d supports up to 1024x1024 tilemaps). So, the problem then becomes finding out what you've hit. After running the raycast, use the hitpoint in tilemap.GetTileIdAtPosition(position, layer) - this returns the tile id at that position your raycast has hit. You can get the sprite name at that position to decide what to do, or GetTileInfoForTileId and the data panel let you set up arbitrary data per tile where you can do what you want.

ivydevelopment

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Need help with animations
« Reply #6 on: August 18, 2014, 12:14:47 am »
Thanks a lot, I'll check into that method but I seem to have found out an alternative just before you posted. It appears as though this works perfectly...I don't suppose it will cause problems later down the road will it?

   void FixedUpdate() {
      float moveLeftRight = Input.GetAxis ("Horizontal");
      rigidbody2D.velocity = new Vector2 (moveLeftRight * walkSpeed, rigidbody2D.velocity.y);
      float moveDownUP = Input.GetAxis ("Vertical");
      rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x, moveDownUP * walkSpeed);
   
      }

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Need help with animations
« Reply #7 on: August 18, 2014, 09:02:43 am »
Ok. I assumed you weren't using physics deliberately. It shouldn't cause any issues.

esdot

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Need help with animations
« Reply #8 on: August 19, 2014, 03:46:18 am »
One approach that might work is animation layers?
You could have 4 maps:
- baseMap
- frame2
- frame3
- frame4

Paint over the water in each of the animation layers, with each frame of the animation.

Then you could just toggle visibility of the layers at like 10fps, and get a animation effect. This has the limitation that all animations run at the same fps, are the same length, and all play in sync, and also requires lots of painting, but performance should be pretty good?