- Home /
2D character bounce off wall / shakes while walking into it
First off i'm new, my character keeps bouncing off the wall when i run into it and makes the camera all shaky, sometimes it even walks through it if the speed of my character is enough.How do i fix it, explain in simple form pls XP.
Answer by Fixel001 · Aug 27, 2020 at 03:19 PM
Solved ..... should not have left using UnityEngine; alone .. there are two more (using) codes up there at the top and i assumed its useless :( .... suffered allot of mental illness and 2 days of my time because i delete them and i'm the one to blame.
the rest i can just follow these steps https://www.youtube.com/watch?v=Cry7FOHZGN4
please PLEASE UN$$anonymous$$ARK this. This is NOT the right answer to your problem, and in fact this is horrible advice.
System.Collections and System.Collections.Generic are the libraries including .net's lists and dictionaries. They have nothing to do with physics collisions.
Unnecessary imports DO NOT improve your code's health at all.
I reiterate, please UN$$anonymous$$ARK this as the right answer. This is HORRIBLE advice.
Answer by YasinJavaid_ · Aug 26, 2020 at 11:10 AM
Hi, Add rigidbody to you character and freeze its rotation constraints those that are shaking.
see image bellow.
Answer by mbro514 · Aug 26, 2020 at 02:13 PM
Try setting the collision detection of your rigidbody to "continuous" rather than "discrete".
https://www.youtube.com/watch?v=LoxXpmJ4BlQ this is the problem the video tryed to fix but i cant seem to follow through because the different ways we used to make our character move. This is my code: using UnityEngine;
public class $$anonymous$$ovementPlayer : $$anonymous$$onoBehaviour { public float moveSpeed; void Start() { moveSpeed = 3f; }
void Update()
{
transform.Translate(moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime, 0f);
}
}
So, the problem is that you're moving the transform directly, rather than adding forces to your rigidbody in order to modify the transform.
Try using the Rigidbody.AddForce() function.
Just a side note: I noticed that you're making a 2D game, but you're using a non-2D rigidbody. For performance reasons, it would be best to use a Rigidbody2D and 2D colliders.
dude thank you for all your wonderful replies :) fixed it after more than 2 days of brain washing. Anyways thank you again <3 turns out deleting two of the (using ) code at the top is a BIG mistake ... the rest is covered in the vid :D
You're welcome! I'm glad that you managed to solve your problem.