- Home /
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613061159im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Virtual Joystick jump in unity2d 0 Answers
Player Movement Relative to Camera? 4 Answers
How to prevent player from moving in air while jumping in place?? 0 Answers
App not reesponding 0 Answers
Fuel bar doesn't work! 1 Answer