- Home /
Question by
xelouissaint · May 18, 2018 at 03:33 PM ·
gameobjectrigidbodytransform.positionontriggerstaygetkeydown
Grab and Drop GameObject with the same Key.
The title basically explains it. Here's what I have so far. I know it works when I change the key in ThrowBall( ).
private void FixedUpdate()
{
ThrowBall();
}
private void OnTriggerStay(Collider other)
{
if (other == ball.GetComponent<Collider>())
{
Debug.Log("GrabBall");
GrabBall();
}
}
void GrabBall()
{
if(holdingBall == true)
{
ball.transform.position = this.transform.position + holdPositionOffset;
ball.GetComponent<Rigidbody>().velocity = Vector3.zero;
ball.transform.rotation = this.transform.rotation;
}
if (Input.GetKeyDown(KeyCode.Space) && holdingBall == false)
{
holdingBall = true;
}
}
void ThrowBall()
{
if (holdingBall == true)
{
if (Input.GetKeyDown(KeyCode.Space))
{
Rigidbody rb = ball.GetComponent<Rigidbody>();
rb.AddForce(500, 500, 0);
Debug.Log("ThrowBall");
holdingBall = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
OnTriggerEnter not working, tried everything! :( (C#) 3 Answers
Move Multiple Directions At Once (ex. forward and right) unity 3d 1 Answer
Rigidbody.MovePosition() is not working if transform.position is just changed 1 Answer
Rigidbody Disable Velocity/Movement? 1 Answer
Two ways to calculate velocity without using Rigidbody, which one is more accurate? 1 Answer