Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kofficoffee · Sep 13, 2018 at 06:47 PM · 2drigidbody2dvelocitytopdownroguelike

How do I make my character move on the Z axis on 2d rigidbody?

Im using rigidbody2ds velocity feature for movement and i need to move my character on the Z axis, problem is I cant figure out how to enable the Z axis for rigidbody 2d. It's a topdown roguelike sprite game with movement similar to binding of isaac. This is my current script.

  using UnityEngine;
  
  /// <summary>
  /// Player controller and behavior
  /// </summary>
  public class PlayerScript : MonoBehaviour
  {
      /// <summary>
      /// 1 - The speed of the ship
      /// </summary>
      public Vector3 speed = new Vector3(50, 50, 50);
  
      // 2 - Store the movement and the component
      private Vector3 movement;
      private Rigidbody2D rigidbodyComponent;
  
      void Update()
      {
          // 3 - Retrieve axis information
          float inputX = Input.GetAxis("Horizontal");
          float inputZ = Input.GetAxis("Vertical");
          float inputY = Input.GetAxis("Y");
  
          // 4 - Movement per direction
          movement = new Vector3(
            speed.x * inputX,
            speed.y * inputY,
            speed.z * inputZ);
  
          // ...
  
          // 5 - Shooting
          bool shoot = Input.GetButtonDown("ArrowRight");
          bool shootup = Input.GetButtonDown("ArrowUp");
          bool shootdown = Input.GetButtonDown("ArrowDown");
          bool shootleft = Input.GetButtonDown("ArrowLeft");
          // Careful: For Mac users, ctrl + arrow is a bad idea
  
          if (shootdown)
          {
              WeaponScriptDown weaponup = GetComponent<WeaponScriptDown>();
              if (weaponup != null)
              {
                  // false because the player is not an enemy
                  weaponup.Attack(false);
              }
          }
          if (shootleft)
          {
              WeaponScriptLeft weaponup = GetComponent<WeaponScriptLeft>();
              if (weaponup != null)
              {
                  // false because the player is not an enemy
                  weaponup.Attack(false);
              }
          }
          if (shootup)
          {
              WeaponScriptUp weaponup = GetComponent<WeaponScriptUp>();
              if (weaponup != null)
              {
                  // false because the player is not an enemy
                  weaponup.Attack(false);
              }
          }
          if (shoot)
          {
              WeaponScript weapon = GetComponent<WeaponScript>();
              if (weapon != null)
              {
                  // false because the player is not an enemy
                  weapon.Attack(false);
              }
          }
  
          // ...
  
      }
  
  
      void FixedUpdate()
      {
          // 5 - Get the component and store the reference
          if (rigidbodyComponent == null) rigidbodyComponent = GetComponent<Rigidbody2D>();
  
          // 6 - Move the game object
          rigidbodyComponent.velocity = movement;
  
          // 7 - Z axis in rigidbody
          
      }
  }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image toddisarockstar · Sep 14, 2018 at 12:32 AM 0
Share

if you are 2D then the only thing that the z axis will do is decide the order of the objects being displayed/ rendered on top of other objects.

2d means 2 axises. you should only be working with x and y reguardless if you are top down or not. y should always be up and down on the screen. the only difference with top down views is you dont use gravity.

avatar image kofficoffee toddisarockstar · Sep 14, 2018 at 04:41 AM 0
Share

Thanks. I moved the project to 3d.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

184 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make my character's movement less floaty? 1 Answer

Adding force to rigidbody2d to slide 1 Answer

Need help understanding advise 1 Answer

Rigidbody2D velocity changes when moving through a platform collider. 1 Answer

Moving colliders that are part of a composite collider 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges