using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
Vector2 moveInput;
Rigidbody2D myRigidbody;
[SerializeField] float runSpeed;
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
}
void Update()
{
Run();
}
void OnMove(InputValue value)
{
moveInput = value.Get<Vector2>();
Debug.Log("moving");
}
void Run()
{
Vector2 playerVelocity = new Vector2(moveInput.x * runSpeed, myRigidbody.velocity.y);
myRigidbody.velocity = playerVelocity;
}
}
But the player is still behaving very weirdly when falling. It is not following gravity⌠Unless gravity is the gravity of a small asteroid.
EDIT: The gravity setting is the same as it ever was. -9.81, the default value. Altering it does nothing
EDIT 2: The instance and the prefab have Gravity scale set to 1.
The player falls down only if his y-velocity is not 0. To see whatâs going on at runtime, please log the velocity into your console while the player is running.
Furthermore, check the tilemap collider. There must not be any gaps. If there are gaps, the player might fall down even if that would not be possible in the real world. The game world in Unity is not the real world, so âimpossibleâ things might happen. Analyse the playerâs environment. Maybe youâll spot a potential problem.
It seems the character is falling at a regular speed. It just feels⌠slow? Maybe itâs just my perception?
EDIT: thatâs âmyRigidbody.velocity.yâ baing logged btw
Fantastic. Now we know that the player has got y-velocity. This is important information because it could have been that something manipulates the playerâs position directly. However, since the y-velocity obviously changes in your game, we can assume that either the gravity pulls the player down, or the code gives the additional player y-velocity, or both.
The slow fall in the beginning is generally correct. The gravity is an accelleration, so the object needs some time before it becomes faster. Similar to a car.
If the game object is extremely slow, thatâs usually because of scale values different from (1, 1, 1). The values in the Rigidbody2D component could also be responsible. If the drag value is very high, the air friction is very high and slows the player down.
Another reason might be that the player is inside a bigger collider. Please check the Inspector of the background tilemap game object. It must not have any collider attached.