EDIT: The problem seems to occur when i add object tag “Platform” and the only thing that uses Platform tag is this:
Code that uses “Platforms” tag
public class PlatfromsMotor : MonoBehaviour {
public float platformMovementSpeed = 0.5f;
public GameObject[] activePlatforms;
public static int activePlatformsInt;
void Update ()
{
activePlatforms = GameObject.FindGameObjectsWithTag("Platform"); //TODO: Move this so that it does not update every frame;
for (int i = 0; i < activePlatforms.Length; i++)
{
GameObject platformToMove = activePlatforms [i];
platformToMove.transform.Translate (Vector2.left * Time.deltaTime * platformMovementSpeed);
}
activePlatformsInt = activePlatforms.Length;
}
}
Hello I am creating a little project, learning about object pooling and creating various things for my endless 2D runner.
The problem that i face is a bit hard to explain, but ive been working for 4 hours trying to figure out WTF is going on and … well, i can’t. So i’m asking for youir help.
First off, my player jumping script:
Player Jumping Script
public class PlayerController : MonoBehaviour {
public float jumpForce = 3;
Rigidbody2D myrigidbody;
public LayerMask groundLayersList;
[SerializeField]
private bool grounded;
public GameObject myBottom;
[SerializeField]
private Collider2D myBottomCollider;
// Use this for initialization
void Start () {
myBottomCollider = myBottom.GetComponent<Collider2D>();
myrigidbody = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update ()
{
grounded = Physics2D.IsTouchingLayers(myBottomCollider, groundLayersList);
if (Input.GetKeyDown ("space"))
{
Jump ();
}
}
private void Jump ()
{
if (grounded)
{
myrigidbody.AddForce (transform.up * jumpForce);
}
}
}
Now, the tricky part. When i create an object, and give it:
layer “Ground”
adding and enabling 2D box collider
everything works fine. Player can jump, and gets checked if grounded when colliding. So this part is working fine.
But when i try to create platforms with sprites its seems like “bottompartofplayer” or “myBottom” never colides with 2D sprites. And im pulling my haird trying to figure out why.
Screenshot:
And yes, every tile is made form a sprite, but sprites have box colliders AND does have a layer:
But the player is sitll not grounded:
Thanks for the help in advance