LookAt() disables the collision of my 2d object
I'm having a very frustrating problem with the LookAt() function. My object (a triangle with a box collider) completely disappeared when I introduced the function in the control script. Can anyone help me? Here's the code:
public string PlayerName;
public float Speed;
private Rigidbody2D thisBody;
// Use this for initialization
void Start () {
Debug.Log("Player control online");
thisBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
thisBody.velocity = movement * Speed;
Vector2 LookPos = new Vector2(Input.mousePosition.y, Input.mousePosition.x);
thisBody.transform.LookAt(LookPos);
Thank you for the attention!
I am having the same issue as you. Was this issue ever resolved?
Answer by Mattitiyahoo · Jun 01, 2017 at 03:38 AM
Right after commenting about if there is a known solution for this, I came upon another solution.
Instead of using transform.LookAt(...), you can use another snippet of code, which can be found here:
http://answers.unity3d.com/questions/585035/lookat-2d-equivalent-.html
Good luck and God speed.
Your answer
Follow this Question
Related Questions
Destorying objects on collsion 1 Answer
2D RigidBody slightly penetrates objects causing a bounce effect. 3 Answers
Early Collision Detection 0 Answers
Collider fires consistently, but Trigger does not? 0 Answers
Why/How 2d tower of blocks collapse? 0 Answers