Question by
Oblit1509 · Apr 02, 2018 at 08:15 PM ·
c#2dsprite2d-platformerbackground
Scrolling background wall collision problem
I'm making a 2d platform
the background scrolls as the player moves
the problem is when the player collides with a wall, if he keeps pressing the key the wall moves despite the player not moving
I'm out of ideas for now on how to resolve this problem
void Update () {
if (constant == false) {
if (Input.GetKey (KeyCode.D) && CameraScript.script.limitX == false) {
plusOffSet += 0.1f;
x = Mathf.Repeat (plusOffSet * speed, 1);
Vector2 offset = new Vector2 (x, savedOffset.y);
GetComponent<Renderer> ().sharedMaterial.SetTextureOffset ("_MainTex", offset);
}
if (Input.GetKey (KeyCode.A) && CameraScript.script.limitX == false) {
plusOffSet -= 0.1f;
x = Mathf.Repeat (plusOffSet * speed, 1);
Vector2 offset = new Vector2 (x, savedOffset.y);
GetComponent<Renderer> ().sharedMaterial.SetTextureOffset ("_MainTex", offset);
}
} else {
plusOffSet -= 0.1f;
x = Mathf.Repeat (plusOffSet * speed, 1);
Vector2 offset = new Vector2 (x, savedOffset.y);
GetComponent<Renderer> ().sharedMaterial.SetTextureOffset ("_MainTex", offset);
}
}
The limitX from camera is to detect the end of the level so it doesn't interfere in the problem
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612155905im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Stop Point objects respawning when reloading level 0 Answers
Keep Top Down 2D camera in bounds of background sprite 3 Answers
How to make a sprite stretch to fill the play space? 1 Answer
Camera Movement Question - How to follow player in Y axis only above certain threshold? 0 Answers
Detect whether a Rigidbody collided with a Trigger 2 Answers