- Home /
Question by
DevMerlin · Dec 08, 2012 at 10:35 PM ·
physicsraycastspherecast
Is it possible to capture a 'free' parent transform, make it into a child, and then move it with the parent?
I'm trying to connect a player to a platform in order to make the player rotate with it. However at the moment I haven't had much luck. The platform already has a detection collider that determines when the player can turn on it, using a invisible cube. However, the platform itself needs to sense the player over it's entire surface. I'm trying a SphereCast but it isn't always working.
// Update is called once per frame
void Update () {
if (_enableCapture)
{
RaycastHit hit;
Ray testRay = new Ray(transform.position, Vector3.up);
if (Physics.SphereCast(testRay, 3f, out hit, 3f))
{
Transform testHit = hit.transform;
checkCapture(testHit);
}
}
}
void checkCapture(Transform _obj)
{
if (_obj.tag == "Player")
{
Control _tagged = _obj.GetComponent<Control>();
_tagged.AmbientSpeed = 0;
_obj.transform.parent = transform.parent;
}
}
The Player is composed of three children, two colliders and a camera. I don't know for sure if parenting the player body will parent all of the children. It gets a little more complicated because after the flip, the parent needs to release everything and allow motion again.
Comment