- Home /
Question by
oyckle · Jun 21, 2020 at 09:40 AM ·
2d2d-platformerplatformerthrowpick up
Does anybody know how to create a consistent pick up and throwing system.,I need help creating a throwing system. (2D)
The system currently works for picking up and throwing on the right side; however, it is inconsistent and I can't throw objects to the left. Any advice?
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Ball")
{
if (ballInHands == false)
{
ballInHands = true;
other.gameObject.transform.position = transform.position + new Vector3(transform.position.x, transform.position.y + offset, transform.position.z);
}
}
}
void Update()
{
if ( ballInHands == true )
{
if (Input.GetKeyDown("space"))
{
ballRB = other.GetComponent<Rigidbody2D>();
ballRB.AddForce(transform.up,ForceMode2D.Impulse);
ballInHands = false;
}
}
Comment
Answer by N-8-D-e-v · Jun 21, 2020 at 03:23 PM
In your addForce statement, you could multiply it by a variable that is either 1 or -1, and set that variable to -1 if your sprite is flipped/ facing the other direction.
Your answer
Follow this Question
Related Questions
Player Tips - Have triggers act independently 1 Answer
Make a 2D jump? 0 Answers
2D Combo Attack 1 Answer