T
T
Timur9757872021-07-12 16:56:24
Unity
Timur975787, 2021-07-12 16:56:24

The player passes through the walls, what to do?

Here is my player movement script (Android game):

public class Player_AD : MonoBehaviour
{
public float speed;
public float ADspeed;
public GameObject player;
public Rigidbody2D rb;
private void Start()
{
rb = GetComponent();
}
void FixedUpdate()
{
if (Input.touchCount > 0 )
{
float deltaPosX = Input.GetTouch(0).deltaPosition.x;
rb.velocity = new Vector2(deltaPosX * Time.deltaTime* speed, rb.velocity.y);
}

}

}
I forgot to say! The player still sticks to the walls. Gave Physics 2D matereal with zero friction, and everything sticks smoothly.
60ec49e0b9ded044451710.jpeg
Here is the link to the game (You will understand better if you look for yourself):
https://play.google.com/store/apps/details?id=com....

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2021-07-12
@freeExec

1. What does Input do in FixedUpdate?
2. What does the documentation say about Rigidbody.velocity?

R
RslaI, 2021-07-12
@RslaI

well, you wouldn’t ask such questions here, but I advise you to check if the sprites have colliders

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question