- Home /
Question by
havezerosalt · Aug 17, 2020 at 07:55 AM ·
movement2d gametopdowndodge
dodge roll in mouse direction in a 2D Top down game,Top down dodge roll in mouse direction
So i have an Movement script and i am currently trying to implement a dodge roll in mouse direction. i tried that one from code monkey but i dont know why the collisions did not work so i am trying to find another one here is my movement script
public Camera cam;
Vector2 mousePos;
private Vector2 moveVelocity;
public float speed;
private Rigidbody2D RB;
void Start()
{
RB = GetComponent<Rigidbody2D>();
}
void Update()
{
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput.normalized * speed;
}
void FixedUpdate(){
RB.MovePosition(RB.position + moveVelocity * Time.fixedDeltaTime);
Vector2 lookDir = mousePos - RB.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
RB.rotation = angle;
}
},so hey i am currently trying to make a top down game where i have an character and its kind of an stealth game currently i am having troubles trying to implement a dodge roll i tried a lot of things but i just dont like every single one of them cause i had troubles with collisions cause it was too fast. this is my movement code which works like intented
public Camera cam;
Vector2 mousePos;
private Vector2 moveVelocity;
public float speed;
private Rigidbody2D RB;
void Start()
{
RB = GetComponent<Rigidbody2D>();
}
void Update()
{
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput.normalized * speed;
}
void FixedUpdate(){
RB.MovePosition(RB.position + moveVelocity * Time.fixedDeltaTime);
Vector2 lookDir = mousePos - RB.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
RB.rotation = angle;
}
}
Comment