- Home /
Question by
kkaaxl99 · Mar 24, 2019 at 09:44 AM ·
charactercontrollerrigidbody2dcollision2d
Character jitter on collision
i have problem with character collision, from what i understand i have to put rigidbody component into calculation of movement instead of jsut transform.position. but have no idea how to put it into my excisting code help appreciated,. im new in c# and still trying wrap head around it
public class playercontrol : MonoBehaviour
{
[SerializeField]
private float speed;
[SerializeField]
private float rotspeed;
public Animator Animator;
public Transform angleTarget;
public Rigidbody2D rb;
void Start()
{
}
void Update()
{
//rotate
Quaternion rot = transform.rotation;
float z = rot.eulerAngles.z;
z -= Input.GetAxisRaw("Horizontal") * rotspeed * Time.deltaTime;
rot = Quaternion.Euler(0, 0, z);
transform.rotation = rot;
//move
Vector3 pos = transform.position;
Vector3 velocity = new Vector3(0, Input.GetAxis("Vertical") * speed * Time.smoothDeltaTime, 0);
// rb.velocity = new Vector2(velocity.x, velocity.y);
pos += rot * velocity;
transform.position = pos;
Comment