Hi,
I am just starting out with unity and I did a little research and a little programming already using C#. Can anyone help me or give me an advice or point me to the right direction on how make two objects collide “smoothly” or “solidly”. Because I have created two spheres and one sphere can move along the x,y, and axis with keyboard keypads like the WASD and the arrows keypads using transform.Translate(); and the other sphere is just there in the 3D space and not moving. Though what I want to happen is when I move the player closer to the other sphere that is just sitting there and doing nothing and when they collide with each other I want both sphere’s to act like solid object. My friend tried this function that I am only familiar with
void OnTriggerEnter(Collider otherObject)
{
if (otherObject.tag == “PlayerBase”)
{
float AmtToMoveX = -Input.acceleration.x * PlayerSpeed * Time.deltaTime;
float AmtToMoveY = -Input.acceleration.y * PlayerSpeed * Time.deltaTime;
///*
if (transform.position.x > 0)
{
AmtToMoveX += 2.5f;
}
else if (transform.position.x < 0)
{
AmtToMoveX -= 2.5f;
}
if (transform.position.y > 0)
{
AmtToMoveY += 2.5f;
}
else if (transform.position.y < 0)
{
AmtToMoveY -= 2.5f;
}
transform.position = new Vector3(AmtToMoveX, AmtToMoveY, transform.position.z);
}
}
The problem with this code is when the sphere that can move and gets closer to the other sphere and its hits the sphere the sphere that moves bounces back off the other sphere. What I want to happen is even though I keep on pushing the sphere that can move onto the other sphere is wont bounce back and it will just remain there close to or sticking the other sphere that should be acting like a solid object.
I have already attached a Sphere Collider on both sphere’s and I have a feeling this component would can help a lot but I do not know how to use it. Or if there is another way to do this other Collider functions that I could use. Any help would be really appreciated. I would really appreciate it more if it is just a guide or advice on how to do it and I will do the coding and logic for it so I can also practice my C# coding along the way. ![]()