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 polda602 · Nov 05, 2015 at 06:03 PM · 2dshootingtopdown

Top Down 2D movement issue

Hello, I got a problem, I think it's no about code but with Unity, but for certainty I put here code. So my problem is when I start a game, the player start move backward (fall down it look like, yes and fixed by checking kinematics but I know the kinematic can be off and it should be working) and my bullets have more force when I'm shooting downward, I don't understand it, why it is doing this. Thanks for help.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour {
 
     public float walkSpeed;
     private float curSpeed;
     public float maxSpeed;
     public float sprintSpeed;
     public float speed;
     public Rigidbody2D rg2d;
     public Rigidbody2D bullet;
     //public Transform bulletSpawn;
     public float bulletSpeed;
     public float xValue;
     public float yValue;
     //private CharacterStat plStat;
     
     void Start()
     {
         //plStat = GetComponent<CharacterStat>();
 
         //walkSpeed = (float)(plStat.Speed + (plStat.Agility/5));
         walkSpeed = speed;
         sprintSpeed = walkSpeed + (walkSpeed / 2);
         
     }
     
     void FixedUpdate()
     {
         curSpeed = walkSpeed;
         maxSpeed = curSpeed * 2;
         if (Input.GetMouseButton (0)) {
             Rigidbody2D bPrefab = Instantiate(bullet, new Vector3(transform.position.x + xValue, transform.position.y + yValue, transform.position.z), Quaternion.identity) as Rigidbody2D;
             
             bPrefab.GetComponent<Rigidbody2D>().AddForce(transform.up * bulletSpeed);
         }
         // Move senteces
         rg2d.velocity = new Vector2(Mathf.Lerp(0, Input.GetAxis("Horizontal")* curSpeed, 0.8f),
                                            Mathf.Lerp(0, Input.GetAxis("Vertical")* curSpeed, 0.8f));
 
 
         var MousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
         Quaternion qot = Quaternion.LookRotation (transform.position - MousePos, Vector3.forward);
         transform.rotation = qot;
     }
 }
 

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rutter · Nov 05, 2015 at 06:55 PM

Sounds to me like your top-down game is simulating gravity as if it were a side-scroller. The game thinks it's pushing objects "down", which from your perspective is "south".

You can remove gravity globally by setting Physics2D.gravityto Vector2.zero (see manual). You can also use this to control the amount and direction of gravity, but in your case it sounds like you'd want to remove it.

If you prefer, you could tell individual rigidbodies to ignore gravity by setting their gravityScale to zero (see manual).

Comment
Add comment · Show 1 · Share
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 polda602 · Nov 05, 2015 at 08:28 PM 0
Share

Thank you, I found the problem, the problem was in a Edit-Project Setting and Physics2D was gravity in Y setted to -9.81, that cause that my character was "falling down"

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

42 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

Related Questions

How to make Enemy shoot at Player Top Down 1 Answer

Instantiate after setting values? 0 Answers

shooting in 2d problem 0 Answers

Top down 2d shooting - XZ rotation 0 Answers

2D Top Down Shooter Shooting Problems 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