I'm a beginner in unity 5, I'm trying to create a 2d game, where I want to put diagonal moves after collisions, currently getting my object after collision is thrown up, but I can not make a diagonal move in any way, my matrix has (0,6) and (0,6) axis x (6,0) and (-6,0), I am working with 2 objects a rectangle and a circle, the circle is inside the rectangle, when the circle hits the walls of the rectangle happens the collision and action. If anyone can help me, he is grateful.
I do not have any diagonal code, just to jump up.
Code: using UnityEngine; using System.Collections;
public class Player: MonoBehaviour { public Vector2 jump = new Vector2 (0,300); private Rigidbody2D rb; private Transform tmf;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody2D>();
// tmf = GetComponent<Transform>();
}
// Update is called once per frame
void Update ()
{
clik();
}
//Dectando colisão de objetos e adicionando ação.
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "piso")
{
jump.y += 100;
rb.velocity = Vector2.zero;
rb.AddForce(jump);
}
}
//Destruir objeto ao clickar
void clik()
{
if (Input.GetMouseButtonDown(1))
{
Destroy(tmf);
}
}
}