Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Henri 1 · Apr 06, 2011 at 05:23 PM · transformvector3resizelocalscale

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

alt text

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Marnix · Apr 06, 2011 at 05:29 PM

  1. Rotate your object so that the scaling direction is on the z-axis.
  2. Scale your object.
  3. 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:

Right 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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Henri 1 · Apr 06, 2011 at 07:10 PM 0
Share

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

avatar image Marnix · Apr 06, 2011 at 10:20 PM 0
Share

@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.

avatar image Marnix · Apr 12, 2011 at 07:14 AM 0
Share

@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.

avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · May 15, 2012 at 10:01 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges