Hi all,
Basically i made two platforms, one of them in horizontal, and the other one is a wall (vertical). I made a boxcollider 2d and a rigidbody for the main player, and i made another boxcollider to the wall, however the collider doesn’t work unless its in horizontal.
Here you have a picture of what i mean.
As you can see, the main player (the white circle) isn’t collisioning, however the enemies are doing it well.
Any idea? please reply.
Thanks.
EDIT:
Here is the script of the player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
private bool Jump = false;
private int Lifes;
public GameObject attack_original;
public GameObject attack_position;
// Start is called before the first frame update
void Start()
{
Lifes = 10000;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(new Vector3(-0.005f, 0.0f));
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(new Vector3(0.005f, 0.0f));
}
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
if (Jump == false)
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0.0f, 300.0f));
Jump = true;
}
/* GetComponent<Rigidbody2D>().AddForce(new Vector2(0.0f, 300.0f));
Jump = true;*/
}
if (Input.GetKeyDown(KeyCode.Space))
{
GameObject.Instantiate(attack_original, attack_position.transform.position, attack_position.transform.rotation);
}
}
void OnCollisionEnter2D(Collision2D _col)
{
switch (_col.gameObject.tag)
{
case "ground":
Jump = false;
break;
case "wall":
Jump = false;
break;
default:
Jump = false;
break;
}
/*if (_col.gameObject.tag == "ground")
{
Jump = false;
}*/
if (_col.gameObject.tag == "Enemy")
{
_col.gameObject.SetActive(false);
Destroy(_col.gameObject, 0.05f);
Lifes = Lifes - 1;
if (Lifes <= 0)
{
Debug.Log("GAME OVER!");
gameObject.SetActive(false);
}
}
}
}