So I have a rigidbody character that is supposed to ride platforms for some sections. I have a code that works, but it also affects how large the character is. Because the character is scaled by 2 on the xy axis, and the platform is scaled by 5 on the x axis.
Is there a way to keep the character on the moving platform, WITHOUT transforming the size?
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.tag == "Mover"){
transform.parent = theCollision.transform;
}
}
function OnCollisionExit(theCollision : Collision){
if(theCollision.gameObject.tag == "Mover"){
transform.parent = null;
}
}
Are you using code to occasionally rescale the player (not just in start?) The problem is when you’re childed, your scale isn’t really your scale.
Suppose your guy is scaled (2,2,1). If you put him in a size (4,4,1) parent, the player won’t change size, but the scale will snap to (0.5, 0.5, 1). That’s the scale in the parent. If you take those #'s, times the parent #'s you get back (2,2,1). Unlike position/localPosition, there’s no easy way to read or set a child’s actual scale (which is what Josh07 writes.)
The problem is, if you set your childed player localeScale (the only scale there is) to (2,2,1), the real scale is suddenly (24, 24, 1*1).
Terrible hack, but if you have to rescale the childed player, could unchild it first: Transform par=player.parent; player.localScale=...; player.parent=par;
. The other way is to divide by the parent scale whenever you are childed (localScale.x = whatIwant/parent.localScale.x;)
I fixed the problem with some 2d trickery. duplicated the platform that was scaled to (5, 1, 1) and changed the new one to (1, 1, 1). Then I just moved the (5, 1, 1) version forward, and increased the box collision on the (1, 1, 1) box to (5, 1, 1). Now you can’t tell the difference. Damn, I wonder if that scaling issue with parenting is going to rear its ugly face any time soon…