- Home /
Moving the grabbed objects changes their scale
I have a objects in a game which I can grab, drop or throw. I have no errors in console. But every time I grab and move the objects, it's like it's being "stretched" and it increases or decreas in size. The first object is a rigidbody with a box collider around it and second object is also a rigidbody but with mesh collider. First object has a scale of (1,1,1) Any help appreciated!
public class ThrowObject : MonoBehaviour
{
public Transform player;
public Transform playerCam;
public float throwForce = 10;
bool hasPlayer = false;
bool beingCarried = false;
public int dmg;
private bool touched = false;
void Update()
{
float dist = Vector3.Distance(gameObject.transform.position, player.position);
if (dist <= 2.5f)
{
hasPlayer = true;
}
else
{
hasPlayer = false;
}
if (hasPlayer && Input.GetButtonDown("Use"))
{
GetComponent<Rigidbody>().isKinematic = true;
transform.parent = playerCam;
beingCarried = true;
}
if (beingCarried)
{
if (touched)
{
GetComponent<Rigidbody>().isKinematic = false;
transform.parent = null;
beingCarried = false;
touched = false;
}
if (Input.GetMouseButtonDown(0))
{
GetComponent<Rigidbody>().isKinematic = false;
transform.parent = null;
beingCarried = false;
GetComponent<Rigidbody>().AddForce(playerCam.forward * throwForce);
}
else if (Input.GetMouseButtonDown(1))
{
GetComponent<Rigidbody>().isKinematic = false;
transform.parent = null;
beingCarried = false;
}
}
}
void OnTriggerEnter(Collider theCollision)
{
if (theCollision.gameObject.tag == "Wall")
{
if (beingCarried)
{
touched = true;
}
}
}
}
Hey! I tested your script and it seems to be working fine. Can you please share some video? so we can understand better about what problem you are facing.
Your answer
Follow this Question
Related Questions
Object sizes from the asset store 1 Answer
Newbiew question: how to size objects? 1 Answer
why the real size of a object doesn't show in the inspector? 0 Answers
How can I scale my object in one direction??? 4 Answers
UI parenting and sizing problem 0 Answers