- Home /
tranform parent makes character blow up in size
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;
}
}![alt text][1]
[1]: /storage/temp/17247-2.png
Well it's generally a good idea to keep most if not all root objects at 1,1,1 scale, but since you haven't, you will either have to make the current bridge object a child of an empty with 1,1,1 scale or manually calculate the scaling to apply to your player. Or figure out another way to move the player without parenting him to the platform.
I had to enlarge my player box, or else it would have been tiny, as seen below. Is there a different way of scaling an object? Because it just doesn't fit in the world, unless the size is doubled.
Answer by Owen-Reynolds · Oct 30, 2013 at 07:00 PM
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 (2*4, 2*4, 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;)
Oh that makes sense... and there's no way to have a parented object adopt the translation, and not the scale?
The script example you showed me makes no sense. Where do I put that code? Can you show me an example in the code I have above? I have no idea what childing is. sigh...
if I set the player back to 1x1x1, is there a script I can write that changes the size to 2x2x2 so that it fits in the world better?
In the Computer Science world, giving something a parent is called "childing" that thing, since you are making it into a child. For example, you "child" the player to the platform (by making the platform the player's parent.) Parenting is making something the parent -- you might parent the player to a gun.
Some Unity people say it the other way, that giving something a parent is "parenting" it.
Answer by Tekksin · Oct 30, 2013 at 08:14 PM
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...