• 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 rando_idot · May 31 at 12:12 AM · playerunity 2dplayer movement

Player character moves downwards in top-down game,Player goes down continously

I'm making a top-down survival game like Don't Starve, but I only have basic Unity knowledge and I'm a dumb boy, so I copied a tutorial (the tutorial in question is www.youtube.com/watch?v=KG_XBc2a6-4)

Every time I start the game, the player character moves downwards very slowly. Constantly. So much so that it falls off the screen if ignored. Is there a way to stop this from happening? The person doing the tutorial didn't seem to have any issues.

The code in question is:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Mouvementsseseseseses : MonoBehaviour
 {
     private Rigidbody2D rb;
     private Animator anim;
     public float MovementSpeed;
     private Vector2 MovementInput;
 
     private void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
         anim = GetComponent<Animator>();
     }
 
 
     private void Update()
     {
         Move();
         Animate();
     }
 
 
 
     private void Move()
     {
         float Horizontal = Input.GetAxisRaw("Horizontal");
         float Vertical = Input.GetAxisRaw("Vertical");
 
 
         if (Horizontal == 0 && Vertical == 0)
         {
             rb.velocity = new Vector2(0, 0);
             return;
         }
 
         MovementInput = new Vector2(Horizontal, Vertical);
 
         rb.velocity = MovementInput * MovementSpeed * Time.fixedDeltaTime;
     }
 
 
     private void Animate()
     {
         anim.SetFloat("MovementX", MovementInput.x);
         anim.SetFloat("MovementY", MovementInput.y);
     }
 }
 

,So, I'm trying to make a top-down survival game, but I'm a dumb boi and I kinda just copied an 8-directional movement tutorial. I copied the code, and did everything the tutorial said to do, but when I play the game, the player character slowly goes down on the y-axis. WHy is this happening? I need help.

The code in question is:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Mouvementsseseseseses : MonoBehaviour
 {
     private Rigidbody2D rb;
     private Animator anim;
     public float MovementSpeed;
     private Vector2 MovementInput;
 
     private void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
         anim = GetComponent<Animator>();
     }
 
 
     private void Update()
     {
         Move();
         Animate();
     }
 
 
 
     private void Move()
     {
         float Horizontal = Input.GetAxisRaw("Horizontal");
         float Vertical = Input.GetAxisRaw("Vertical");
 
 
         if (Horizontal == 0 && Vertical == 0)
         {
             rb.velocity = new Vector2(0, 0);
             return;
         }
 
         MovementInput = new Vector2(Horizontal, Vertical);
 
         rb.velocity = MovementInput * MovementSpeed * Time.fixedDeltaTime;
     }
 
 
     private void Animate()
     {
         anim.SetFloat("MovementX", MovementInput.x);
         anim.SetFloat("MovementY", MovementInput.y);
     }
 }
 


Big brain stuff. Also, the tutorial I followed is this: www.youtube.com/watch?v=KG_XBc2a6-4

Comment
Add comment · Show 1
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 Caeser_21 · May 31 at 05:04 AM 0
Share

Is your gravity scale set to 0 on your RigidBody2D

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

183 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

Related Questions

Stopping object rotating at a certain rotation 1 Answer

Put objects in (front) and direction on a sphere 0 Answers

How to make 2D Player dash towards mouse position in a straight line? 1 Answer

Local player always at same position 2 Answers

All Unity Engine games' controls not working 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