# 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

1. Rotate your object so that the scaling direction is on the z-axis.

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.

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.

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

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

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