Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Why does 2D vector use vector3 instead of vector2

Discussion in '2D' started by jpom001, Dec 27, 2020.

Thread Status:
Not open for further replies.
  1. jpom001

    jpom001

    Joined:
    Dec 3, 2020
    Posts:
    69
    Why does the rigidbody2D.addForce example in the docs, use a Vector3 to describe the position of the the object here:
    https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html
    I assumed 2D games would only use 2D objects. I've noticed a few code snippets online for move and jump scripts that used Vector3s in them. If I am creating a 2D platform game, where my directions are only up,down,left,right, is it correct to use a Vector2 or should I use Vector3?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    They're interchangeable. In Unity, there's functionality no difference between a 2D game and a 3D game - it's just a different camera perspective.

    For the most part, you're fine with just using the x and y axes, but there can be some cases where z-axis depth is useful.
    For instance, animation. If you want to make any sort of semi-realistic walking animation in a top-down 2D game, you can still animate the moving parts like you would in 3D animation, and it would still look good in the top-down camera perspective.
     
    johelpiro likes this.
  3. ANoobDev

    ANoobDev

    Joined:
    Jul 27, 2021
    Posts:
    2
    True depth, true action.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    If you're going to necro a thread, please in the very least, add some value to it.

    Let's close this thread.
     
    Kurt-Dekker likes this.
Thread Status:
Not open for further replies.