- Home /
Resize object forward instead of along the z axis
Hi there!
Just want to find out.
How do I resize an object from its origin point, in a forward direction within a raycast?
if I use
MyObject.transform.localScale = new Vector3(0, 0, (hit.distance*0.025));
my object resizes, but at the original position along the z axis (see picture).
Note: I'm using JavaScript
Answer by Marnix · Apr 06, 2011 at 05:29 PM
- Rotate your object so that the scaling direction is on the z-axis.
- Scale your object.
- Rotate your object back.
Additional info
To scale an object in some way, doesn't matter what way: First put it on the origin before scaling.
In the viewing pipeline the following aspect is very important: Scale -> Rotate -> Translate. This is how it goes by default. If you want to scale it in some strange way, rotate your object to the right position (or translate even). After that, you can scale it. Then, return it to your original position.
For your case
Your object is in the middle, which will scale in the z-axis symmetrically. So: Translate your object to one side of the xy-plane.
Update
void Update() { Vector3 oldP = MyObject.transform.position; Quaternion oldR = MyObject.transform.rotation;
// set the object to the origin
MyObject.transform.position = new Vector3(0,0,halfYourObjectsThickness);
MyObject.transform.rotation = Quaternion.identity;
// scale your object, forgot how to do that
// Your ScaleMatrix will contain a scale in the Z direction.
MyObject.transform = ScaleMatrix * MyObject.transform;
// set your object back to where it came from.
MyObject.transform.position = oldP;
MyObject.transform.rotation = oldR;
}
And even a picture for further understanding, where the right axis is the Z-axis:
And try googling for this: 3d transformations
There are a lot of fun things to do with matrices, which are not just localScale
. If you have questions: Ask, and don't say: it doesn't work. Try to understand it, then implement it.
Translate only causes the object to move in the suggested direction. Did script as follow:
$$anonymous$$yObject.transform.Translate(Vector3.forward * (Time.deltaTime*10));
to test
@Dawg: Yes of course, it will only move. But you can not simply scale your object, because you want a special scale. Translate your object to one side, scale it, and translate it back in one frame. I'll update my answer.
@Dawg: Did this help you, or do you still have some questions? If the question is ok, please press the accept button next to the answer.
Answer by huttyman · May 15, 2012 at 11:31 AM
I think you just create empty object that have your cylinder edge at center of that "empty Object" then scale the empty object
I hope this will help even if it's maybe too late TT
Answer by huttyman · May 15, 2012 at 11:28 AM
I think you just create empty object that have your cylinder edge at center of that "empty Object" then scale the empty object
I hope this will help even if it's maybe too late TT
Answer by huttyman · May 15, 2012 at 08:44 AM
I think you just create empty object that have your cylinder edge at center of that "empty Object" then scale the empty object
I hope this will help even if it's maybe too late TT
Ehmm, i don't see the reason for this post... $$anonymous$$arnix explained that already very detailed. BTW: the question has been posted over a year ago...
Your answer
Follow this Question
Related Questions
How to determine speed of an object when using transform.position 2 Answers
Issue's With Positioning 0 Answers
Move an object forward and not up? 1 Answer
Moving by rotation of objects 0 Answers
What is the reasoning of multiplying by Time.deltaTime 1 Answer