- Home /
Player not going in right direction when parented
How do I make my player when it collides with circle rotates with it and when I press left click it launches and I have to hit another circle. So far I made player move up and when it collides it kinda goes with circle but when i try again to launch it it goes in random direction. Here's the code and some of the pictures. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class player : MonoBehaviour
{
public Vector2 throwForce;
private Rigidbody2D rb;
private CircleCollider2D circleCollider;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
circleCollider = GetComponent<CircleCollider2D>();
}
private void Update()
{
if(Input.GetMouseButtonDown(0))
{
rb.AddForce(throwForce, ForceMode2D.Impulse);
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.collider.tag == "Circle")
{
rb.velocity = new Vector2(0, 0);
rb.bodyType = RigidbodyType2D.Kinematic;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How do i prevent the player from dragging a ui element off screen? 1 Answer
Player object falling through game environment, collision not detected with ground 0 Answers
Pain Screen Flash UI and fades 1 Answer
collision wont work 1 Answer
How do you change gravity with a press of a button? Unity 2D 2 Answers