- Home /
AddForce to x axis when mouse position is close to x axis ? And if closer to x axis the more addforce
(2D game) So my player has an Addforce type of a knock-back in the opposite direction of a mouse position after pressing fire1 button (shotgun effect), and it works, but I want to add more force when player is shooting with mouse position in x axis, so that it is more knockback on sides rather then top and bottom. Player In combination with jumping mechanic knock'sback to far away in y axis.
Rigidbody2D Rigidbody2D = m_Rigidbody2D.GetComponent<Rigidbody2D>();
Vector2 direction = Rigidbody2D.transform.position - firePoint.transform.position;
Rigidbody2D.AddForce(direction * knockback);
I dont know how to come about this problem, maby doing an array of values ?
Your answer
Follow this Question
Related Questions
AddForce knockback x axis according to mouse.position more then y axis (2D game) 0 Answers
Acceleration and Max Speed on 2D Object 0 Answers
Adding force to object hit by sword 0 Answers
Need Help with MousePos and dashing 0 Answers
Adding force to mouse position adds force relative to screen center 0 Answers