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
0
Question by Arishtanemi1998 · Jan 14, 2015 at 05:32 AM · gameobjecttransformcubeforwardside

change the front point or head of a GameObject

i hav a cube gameobject of which i need to change the front position or head or its tip.i use a transform .foward function on the object like this:-

  transform.position += transform.forward * Time.deltaTime * speed;

the problem is that the cube moves along the middle of one of its sides(fig-1)and not along one of its corners (fig-2).please help. alt text

2.png (8.6 kB)
1.png (7.3 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ElDo · Jan 14, 2015 at 06:05 AM

you could either Change the direction where to move your cube, or Change the direction. What your code does is move the cube along it's Forward direction (Z-Axis) which Points to one of its sides. Now you could Change that Forward direction to Point somewhere else and Keep your move code like this:

 transform.Forward=new Vector3(0,1,1);

or you Keep the directions of the cube (Forward, Up and Right) but Change your move code to whereever you want it to move to like that:

 transform.Position+=new Vector3(0,1,1) * Time.deltaTime * Speed;


Comment
Add comment · Show 5 · 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 Arishtanemi1998 · Jan 14, 2015 at 09:19 AM 0
Share

sorry dosent work because i only need the object to move from ONE specific corner and not all corners and adding your code makes it come to the origin

avatar image ElDo · Jan 14, 2015 at 05:04 PM 0
Share

so you only want to move one Corner and leave the other Corners where they are and deform the cube or what? then you Need to get the Vertices first and move them respectively like:

 //get the mesh data first
 $$anonymous$$esh mesh = transform.GetComponent<$$anonymous$$eshFilter>().mesh;
 //then get all the Vertices
 Vector3[] Verts=mesh.vertices;
 //now move your Vertice(s)
 Verts[0]+=transform.Forward;
 mesh.vertices=Verts;
 

this should do the trick

avatar image Arishtanemi1998 · Jan 15, 2015 at 08:21 AM 0
Share

that just moves the vertice only where as simultaniously the cube must also move

avatar image Arishtanemi1998 · Jan 15, 2015 at 08:34 AM 0
Share

sorry this only changes one vertice where as i want the cube to also follow the same vertice around

avatar image ElDo · Jan 15, 2015 at 08:59 PM 0
Share

so then it's the very first answer just except that you wouldn't use new Vector3(0,1,1) you'd use new Vector3(1,1,1) for the Corner between UP,FORWARD and RIGHT. the code would be:

 transform.position+=new Vector3(1,1,1)*0.02f*Time.deltaTime;

if you would want to move it along another Corner you just have to Change the Vector3 to (1,1,-1),(1,-1,1),(1,-1,-1),(-1,1,1),(-1,1,-1),(-1,-1,1) or (-1,-1,-1) depending on which Corner of the 8 this cube has you want to use towards.

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

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Moving game objects 2 Answers

Sorting list of Transforms 1 Answer

Collision delete 1 Answer

GameObject not working with variable in C# script 3 Answers

Cube moving through rigid body 2 Answers


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