Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - nicktp491

Pages: [1]
1
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: November 06, 2013, 06:11:40 pm »
Here is my project folder zipped up on dropbox.  If anyone can figure out how to get my collision to work it would be most appreciated.

edit: removed link. Only post links to projects in the private support forum.

Use number 3 as that was the most recent scene I was using.  All I want to do is have the player collide using the colliders and not by looking at each tiles ID for where the player is going to be next.

2
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: October 06, 2013, 01:43:44 am »
Its quite impossible to guess whats gone wrong from your description - there are so many variables at play here. If its drifting, then perhaps you have a rigidbody there that shouldn't be there?

The only rigidbody that I have is on the player.  Also I just realized that the player can no longer collide with the top and bottom collision walls.  If you know of a solution to the corners problem I could probably use that, although I would like to know how the guy in this video is able to get it to work but I cant.

http://unity3d.com/learn/tutorials/modules/beginner/physics/colliders

3
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: October 05, 2013, 08:09:18 pm »
I tried RayCasting and I was able to get closer to what I was trying to do but unfortunately I still came up with the same problem, which was the corners.  I've been messing around with tutorials and now I have a new problem.  I have the collider of the player not set to is trigger and the player can't leave the area now, but two things occur.  The first is that it looks like the player is fidgeting when colliding with the wall.  And the other is that after I let go of the key command to move him, he starts drifting in the opposite direction.

4
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: October 05, 2013, 03:57:42 am »
I've looked into character controller but it seems to use capsule collision instead of box collision.  Is their a way to change it because it seems from what I've seen it needs to be capsule collision.
Here's some pics to better see what I'm working with.  To explain again I'm looking for a way to only keep it on the tiles that are imaged and what I have been doing so far is stopping it from going onto the black tiles that surround the imaged tiles.

Here's the players box collider pic:
http://img31.imageshack.us/img31/9646/dl.png

And here's the tilemap collider pic:
http://img69.imageshack.us/img69/370/t8ch.png

5
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: October 05, 2013, 03:26:02 am »
I've looked into character controller but it seems to use capsule collision instead of box collision.  Is their a way to change it because it seems from what I've seen it needs to be capsule collision.

6
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: September 24, 2013, 11:09:15 pm »
Not sure what I should be grasping from the links information because the downloadable file doesn't seem to load in unity.  This is my code right now and it some what accomplishes what I wanted to do but I would like to use the collisders in a way that if another collider has a point that is the same with the players collider, then figure out how to stop the player from moving in that direction.  With my code I still get some instances where the player is somewhat in an area he shouldn't be but other then that it works fine.  Any improvements on this code is also appreciated.

Code: [Select]
using UnityEngine;
using System.Collections;

public class PlayerScriptV2 : MonoBehaviour {

#region variables
public tk2dSpriteAnimator currentAnimation;
public tk2dTileMap tileMapFinder;

#region movement variables
public bool wasWDown = false;
public bool wasADown = false;
public bool wasSDown = false;
public bool wasDDown = false;
public bool isRunning = false;
public float iSpeed = 1.0f;
public bool blockedL = false;
public bool blockedR = false;
public bool blockedU = false;
public bool blockedD = false;
public int currentTileId;
public int currentTileX;
public int currentTileY;
public int leftMiddleTileId;
public int leftTopTileId;
public int leftBottomTileId;
public int rightMiddleTileId;
public int rightTopTileId;
public int rightBottomTileId;
public int upMiddleTileId;
public int upLeftTileId;
public int upRightTileId;
public int downMiddleTileId;
public int downLeftTileId;
public int downRightTileId;
#endregion
#endregion

// Use this for initialization
void Start () {
currentAnimation = GetComponent<tk2dSpriteAnimator>();
tileMapFinder = tk2dTileMap.FindObjectOfType(typeof(tk2dTileMap)) as tk2dTileMap;
}

// Update is called once per frame
void Update () {

tileMapFinder = tk2dTileMap.FindObjectOfType(typeof(tk2dTileMap)) as tk2dTileMap;

#region motion control
#region load needed variables
currentTileId = tileMapFinder.GetTileIdAtPosition(gameObject.collider.bounds.center, 0);
tileMapFinder.GetTileAtPosition(gameObject.collider.bounds.center, out currentTileX, out currentTileY);

//collider draws from bottom-left to top-right
leftTopTileId = tileMapFinder.GetTileIdAtPosition(gameObject.collider.bounds.min, 0);
leftMiddleTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.min.x,gameObject.collider.bounds.center.y, gameObject.collider.bounds.center.z) , 0);
leftBottomTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.min.x,gameObject.collider.bounds.max.y, gameObject.collider.bounds.center.z) , 0);

rightTopTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.max.x, gameObject.collider.bounds.min.y, gameObject.collider.bounds.max.z), 0);
rightMiddleTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.max.x,gameObject.collider.bounds.center.y, gameObject.collider.bounds.center.z) , 0);
rightBottomTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.max.x,gameObject.collider.bounds.max.y, gameObject.collider.bounds.center.z) , 0);

upLeftTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.min.x, gameObject.collider.bounds.max.y, gameObject.collider.bounds.center.z), 0);
upMiddleTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.center.x,gameObject.collider.bounds.max.y, gameObject.collider.bounds.center.z) , 0);
upRightTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.max.x, gameObject.collider.bounds.max.y, gameObject.collider.bounds.center.z), 0);

downLeftTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.min.x, gameObject.collider.bounds.min.y, gameObject.collider.bounds.center.z), 0);
downMiddleTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.center.x,gameObject.collider.bounds.min.y, gameObject.collider.bounds.center.z) , 0);
downRightTileId = tileMapFinder.GetTileIdAtPosition(new Vector3(gameObject.collider.bounds.max.x, gameObject.collider.bounds.min.y, gameObject.collider.bounds.center.z), 0);
#endregion

#region if wall is blocked test
//leftBlock test
if((leftMiddleTileId == 12 && leftTopTileId == 12 && leftBottomTileId == 12) || (leftMiddleTileId == 12 && leftTopTileId != 12 && leftBottomTileId == 12) || (leftMiddleTileId == 12 && leftTopTileId == 12 && leftBottomTileId != 12))
{
blockedL = true;
}
else
{
blockedL = false;
}
//rightBlock test
if((rightMiddleTileId == 12 && rightTopTileId == 12 && rightBottomTileId == 12) || (rightMiddleTileId == 12 && rightTopTileId != 12 && rightBottomTileId == 12) || (rightMiddleTileId == 12 && rightTopTileId == 12 && rightBottomTileId != 12))
{
blockedR = true;
}
else
{
blockedR = false;
}
//upBlock test
if((upMiddleTileId == 12 && upLeftTileId == 12 && upRightTileId == 12) || (upMiddleTileId == 12 && upLeftTileId != 12 && upRightTileId == 12) || (upMiddleTileId == 12 && upLeftTileId == 12 && upRightTileId != 12))
{
blockedU = true;
}
else
{
blockedU = false;
}
//downBlock test
if((downMiddleTileId == 12 && downLeftTileId == 12 && downRightTileId == 12) || (downMiddleTileId == 12 && downLeftTileId != 12 && downRightTileId == 12) || (downMiddleTileId == 12 && downLeftTileId == 12 && downRightTileId != 12))
{
blockedD = true;
}
else
{
blockedD = false;
}
#endregion

#region input capture
if(Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S))
{
currentAnimation.Play("Run_Up");
if(!blockedU)
{
transform.Translate(0,((iSpeed * Time.deltaTime)+0.1f),0);
}
wasWDown = true;
wasADown = false;
wasSDown = false;
wasDDown = false;
isRunning = true;
}
if(Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.D))
{
currentAnimation.Play("Run_Left");
currentAnimation.SetFrame(0);
if(!blockedL)
{
transform.Translate(-((iSpeed * Time.deltaTime) + 0.1f),0,0);
}
wasWDown = false;
wasADown = true;
wasSDown = false;
wasDDown = false;
isRunning = true;
}
if(Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.W))
{
currentAnimation.Play("Run_Down");
if(!blockedD)
{
transform.Translate(0,-((iSpeed * Time.deltaTime) + 0.1f),0);
}
wasWDown = false;
wasADown = false;
wasSDown = true;
wasDDown = false;
isRunning = true;
}
if(Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A))
{
currentAnimation.Play("Run_Right");
if(!blockedR)
{
transform.Translate(((iSpeed * Time.deltaTime) + 0.1f),0,0);
}
wasWDown = false;
wasADown = false;
wasSDown = false;
wasDDown = true;
isRunning = true;
}
if(Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.D))
{
currentAnimation.Play("Run_LeftDown");
if(!blockedD)
{
transform.Translate(0,-((iSpeed * Time.deltaTime) + 0.1f),0);
}
if(!blockedL)
{
transform.Translate(-((iSpeed * Time.deltaTime) + 0.1f),0,0);
}
wasWDown = false;
wasADown = true;
wasSDown = true;
wasDDown = false;
isRunning = true;
}
if(Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A))
{
currentAnimation.Play("Run_RightDown");
if(!blockedD)
{
transform.Translate(0,-((iSpeed * Time.deltaTime) + 0.1f),0);
}
if(!blockedR)
{
transform.Translate(((iSpeed * Time.deltaTime) + 0.1f),0,0);
}
wasWDown = false;
wasADown = false;
wasSDown = true;
wasDDown = true;
isRunning = true;
}
if(Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D))
{
currentAnimation.Play("Run_LeftUp");
if(!blockedU)
{
transform.Translate(0,((iSpeed * Time.deltaTime) + 0.1f),0);
}
if(!blockedL)
{
transform.Translate(-((iSpeed * Time.deltaTime) + 0.1f),0,0);
}
wasWDown = true;
wasADown = true;
wasSDown = false;
wasDDown = false;
isRunning = true;
}
if(Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.A))
{
currentAnimation.Play("Run_RightUp");
if(!blockedU)
{
transform.Translate(0,((iSpeed * Time.deltaTime) + 0.1f),0);
}
if(!blockedR)
{
transform.Translate(((iSpeed * Time.deltaTime) + 0.1f),0,0);
}
wasWDown = true;
wasADown = false;
wasSDown = false;
wasDDown = true;
isRunning = true;
}

if(isRunning)
{
if(!Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
{
isRunning = false;
}
}
else
{
if(wasWDown && !wasADown && !wasDDown && !wasSDown)
{
currentAnimation.Play("Idle_Up");
currentAnimation.SetFrame(0);
}
if(wasADown && !wasWDown && !wasSDown && !wasDDown)
{
currentAnimation.Play("Idle_Left");
currentAnimation.SetFrame(0);
}
if(wasDDown && !wasWDown && !wasSDown && !wasADown)
{
currentAnimation.Play("Idle_Right");
currentAnimation.SetFrame(0);
}
if(wasWDown && wasADown && !wasDDown && !wasSDown)
{
currentAnimation.Play("Idle_LeftUp");
currentAnimation.SetFrame(0);
}
if(wasWDown && !wasADown && wasDDown && !wasSDown)
{
currentAnimation.Play("Idle_RightUp");
currentAnimation.SetFrame(0);
}
if(wasSDown && !wasADown && !wasDDown && !wasWDown)
{
currentAnimation.Play("Idle_Down");
currentAnimation.SetFrame(0);
}
if(wasSDown && wasADown && !wasDDown && !wasWDown)
{
currentAnimation.Play("Idle_LeftDown");
currentAnimation.SetFrame(0);
}
if(wasSDown && !wasADown && wasDDown && !wasWDown)
{
currentAnimation.Play("Idle_RightDown");
currentAnimation.SetFrame(0);
}
}
#endregion
#endregion
}
}

7
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: September 20, 2013, 05:55:42 pm »
I have a sprite that moves in all directions but looks like a top down game.  Kind of like the pokemon ranger games.  (Actually using their sprites for testing).  And I need to know is when the animated sprite collides with a tile with a box collider and stop them from going past it.  Right now for testing purposes I have a square tile map with the outlining tiles being tiles with a box collider on them.

8
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: September 20, 2013, 04:16:59 pm »
I see you point about using too many prefabs.  Although regarding your previous:
If you're doing collisions using bounds.intersects, then you could probably get away with simply checking renderer bounds. I.e. gameObject.renderer.bounds.Intersects(...).
I tried calling from gameobject.renderer.bounds but every time it said that there is no renderer attached to the TileMap.  Not sure why.

Also I tried your onTriggerEnter/onTriggerStay/onTriggerExit but it doesn't seem to be working for me.  Or at least it is not running the same amount of time as the update. With the function:

//variablespublic bool blockedLeft = false;
public Vector3 leftSideOfPlayerCollider;
//function
void OnCollisionEnter(Collision other)
{
      if(other.collider.bounds.Contains(leftSideOfPlayerCollider)
      {
            blockedLeft  = true;
      }
}

But Contains seem to look at everything inside my tile map because I'm using a test tile map that 13 by 10.  I also have a tile that goes around the outline of the tilemap which has a box collider on the sprite.  So Contains looks at everything instead of just the stuff that’s inside the mesh collider of the tile map render data chunk.

I would use Intersects but then it wouldn’t tell me what side of the player is intersecting on.  (I was an XNA user up until Microsoft decided to pretty much kill it and did much of my boxed collisions using Rect.Left/Right/etc..)

Is there a more effective way to go about this or am I running around in circles trying to use the bounds?
If so what should I be using instead because I would like to use the actual collider but it seems my only success so far was with looking at the tile in the next position that I am traveling towards.

9
Support / Re: tk2dTileMap tiles collision with tk2dSprite?
« on: September 20, 2013, 01:10:05 am »
I was actually using the GetTileAtPosition before this, but I did actually find another way to do it by giving one of the tiles a prefab of itself with the collider that I needed to reference for my collisions.  This solution works for me so I though I would post my results of research so that others could benefit. I'm not sure if this will cause any future problems so if you know of anything that might occur that would be helpful.

10
Support / tk2dTileMap tiles collision with tk2dSprite?
« on: September 19, 2013, 07:06:15 pm »
I've done most of my collisions based on attaching a collider and then calling,

if(gameObject.collider.bounds.Intersects(otherObject.collider.bounds))
{
        //Do Something
}

but I cant seem to figure out how to call for the collision detection of a sprite and a tile maps individual sprites that make up the tile map.

What should i be referencing before getting to the .collider.bounds in my code, because I feel Itellisense searching is getting me no where.

11
Support / Re: Tilemap Tile Changing
« on: September 06, 2013, 03:11:40 am »
Yes, you need to update by calling Build() after changing the tile. It's done this way so you can change lots of them if needed and then update the mesh at the end.

Calling Build(); doesn't seem to do anything.  I did find a thread that said the the tile map feature wasn't completed and wasn't supported so it may be one of those things that haven't been tested yet.  But I did create an alternative for what I needed accomplished.  Thanks for your suggestion though.

12
Support / Tilemap Tile Changing
« on: September 05, 2013, 12:11:58 am »
I wanted to be able to change a tile in the tile map during run time and it seems to be working but the visual representation is not changing.  Here's the code I am using.

tk2dTileMap temp;
temp = gameObject.GetComponent<tk2dTileMap>();
temp.SetTile(1,1,0,16);

It's changing the tile because I have this line of code:
GUI.Label(new Rect(10, 90, 200, 20), "tile id = " + tileMapFinder.GetTileIdAtPosition(v3Position,0));
And it tells me that the value of the tile id did change, but the sprite didn't.

Do I need to somehow update the TileMap's render data or am I trying to change the Tilemap's sprite incorrectly?

13
Support / Re: Setting a tk2dSprite scale in scripting
« on: September 03, 2013, 01:40:46 am »
Don't use the transform, use the scale property on the tk2dSprite class.
I've seen the tk2dSprite class but I am unsure how to call from it because I am using a different script that I attached to the object.

It's like anything in Unity where you need a script to talk to another component, either use GetComponent in your script or make a variable that you can drag-and-drop the sprite onto in the inspector. See the Unity docs for details.

c# example of getting the sprite component and changing the scale to 2:
Code: [Select]
tk2dSprite sprite;
sprite = GetComponent<tk2dSprite>();
sprite.scale = new Vector3 (2,2,2);

But as Unikron said, changing the scale on the transform should work. You will most likely need to attach an example so someone can check it out and see what is wrong.

Yes this helped a lot I was able to get it working after changing around a few variables in my code.  Thank everyone for posting to help me with me scripting problem.

14
Support / Re: Setting a tk2dSprite scale in scripting
« on: September 01, 2013, 07:18:37 pm »
Don't use the transform, use the scale property on the tk2dSprite class.
I've seen the tk2dSprite class but I am unsure how to call from it because I am using a different script that I attached to the object.

You can (and probably should) use the scale property on the tk2dSprite class.
But if you're changing transform.localScale and it isn't physically changing scale... do you have "static" ticked on it or the parent? Thats the only thing I can think of that could cause this...
That is what I was using and it wasn't changing the scale. Although if I used Debug.Log() to check the value, it was changing just not showing the change on the object.  Also I don't have static checked on the object.

15
Support / Setting a tk2dSprite scale in scripting
« on: September 01, 2013, 03:34:18 am »
Honestly I've been trying to figure this out for days with no luck.  All I wanted to do was change the scale of a sprite while the game is running, but it seems that once the game is running the transform scale of the gameObject are set as they are.  I've tried changing the localScale the lossyScale by using .Set and nothing changes during the game.  I know the values are changing but the image itself stays the same.  Any help is thanked for in advance.

Pages: [1]