- Home /
Make gameobject size always be the same
I have a 3d world, perspective camera, moving character and one gameobject, which I want to seem always the equal size on screen(for example, half of game screen size). If person is too far from that go, go's size should be larger, if too near, it's size should be smaller, so player will see it exactly the same size.
void Update {
//how to adjust it's size?
}
Store a reference to your player and the gameObject. From the transform.position of those objects, calculate a magnitude. Then use that magnitude as a modifier to the gameObjects scale.
What is the object? Have you considered an orthographic camera?
Is there a reason you need there to be a perspective camera? As Tarlius pointed out, an ortho camera would serve you better
No, I want exactly perspective camera, I want my object(it looks like a arrow) to be at the same place with the same size! Ortho-camera is impossible to use, because it's real 3d world.
hmm, no votes on my suggestion, but have you thought about it / tried it? The scale is modified based on the distance between the objects, the distance is the magnitude of the difference between the 2 vectors. If this isn't resolved by tomorrow I shall write up a demonstration to prove the concept.
Answer by Loius · Mar 18, 2013 at 06:22 PM
var size : float = (Camera.main.transform.position - transform.position).magnitude;
transform.localScale = Vector3(size,size,size);
You'll probably want to multiply size by something, or make the object a child of an object scaled to keep its size where you want it.
yeah, i've done something like it:
transform.localScale = Vector3(size,size,size) * $$anonymous$$UL;
but had problems, when character is too close to object. As a temporary solution I've done something like: if we are too close to object, show const size, otherwise show as you wrote. thank you for your solution!
Answer by PAHeartBeat · Mar 18, 2013 at 03:55 PM
Hi Why you not try to follow your moving charter using camera (cam follow script), if camera and object will be at same distance every time, your character seem always the equal size.
you will find the script on unity communify
edit: you can also find that smooth follow script on FPS Controller which is inbuilt in Unity
You seem to misunderstand my question. I do have following camera on my character. And I have a gameobject which always stays on the same position(it's like an arrow pointer to player). I want to make this object always look the same size.
Answer by Neurolitic · Mar 20, 2014 at 03:14 PM
why not just make the gameobject a child of the main camera? .. fixed distance between the gameobject and the main camera means you do not need to scale the gameobject.
Your answer