2D Toolkit Forum
2D Toolkit => Support => Topic started by: Hapistorique on December 09, 2012, 03:24:32 pm
-
Hey,
I have an issue with the tk2d camera, I started using it yesterday and it's really strange :
All the sprites are really large, but the colliders are really small in Z :
(http://puu.sh/1yZ6A)
Is it supposed to look like that ?
My main issue is with a collider, I'm simply making a fireball spell, when the fireball touch the ground or anything, it destroy itself
So I have this code :
void OnCollisionEnter(Collision collision){
Destroy(transform.gameObject);
Debug.Log("Fireball collided");
}
really simple for now, but it's not working, the collision is only detected sometimes, when the other sprite is moving :-\
All the sprites and the ground cube are on the same layer
If this can help I'm using iTween to move the sprite
iTween.MoveTo(newFireBall.gameObject, new Vector3(curMousePosition.x, -0.1f, 0), 5 );
When using rigidbody and leting the object fall by itself to the ground it works fine
-
Yes thanks for posting the line you were using to move it - the issue has all to do with that :)
The thickness of the collider isn't the issue here, but you could certainly increase it. In sprite collection editor, go into settings, change collider depth. The default is 0.1 units, which is why it looks thin with with the tk2dCamera enabled.
Back to the issue, do you have a rigidbody attached to this, and is it set to kinematic?
-
No I'm using rigidbody with gravity, I should use kinematic ?
I have the exact same issue with arrows, they should disappear and send damage to the gameobject collided
When the ennemy is moving, it works fine, but when it's standing still it goes right thought it and doesn't trigger oncollisionenter
I tried using rigidbody + kinematic for all but it doesn't do much
EDIT : It seems like it works when using rigidbody without gravity or kinematic or gravity only
Arrow.cs : (moves the arrow, detects collision)
void Update () {
transform.Translate(new Vector3(0.01f,0,0));
}
void OnCollisionEnter(Collision col){
if(col.collider.CompareTag("Enemy")){
//col.gameObject.SendMessage("ChangeHealth", -archerScript.GetAttackPower());
Destroy(transform.gameObject);
}
}
Code to spawn an arrow :
public override void Attack(GameObject target){
if (curTarget != null && attackTimer >= attackDelay){
attackTimer = 0;
soundManager.SendMessage("PlayOnce", "meleeAttack");
tk2dSprite newArrow = Instantiate(arrow, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity) as tk2dSprite;
}
-
You can't move a non-kinematic rigid body with iTween, etc. If you did that you are likely to miss lots of (most) collisions. If you need to move a non-kinematic rigidbody, use Rigidbody.AddForce (http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html) instead.