I need transform my variable Transform in Vector2 but i don’t know how to do it
my Script:
public int jump;
private bool IsGrounded;
public Transform foot;
public LayerMask ground;
void Update()
{
IsGrounded = Physics2D.OverlapCircle(foot, 0.3f, ground);
if (IsGrounded && Input.GetKeyDown(KeyCode.W))
{
GetComponent().AddForce(new Vector2(0, jump));
}
}
someone plz help me?
Vector2 vectorName = new Vector2(foot.position.x, foot.position.y);
IsGrounded = Physics2D.OverlapCircle(foot.position, 0.3f, ground);
Just like that. “foot” is a Transform component. It has a property called “position” which returns the position of that object as Vector3. A Vector3 can be implicitly converted into a Vector2 which is required by Physics2D.OverlapCircle. It will simply drop / ignore the z component.
1 Like