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 Henrique · Jun 16, 2010 at 05:38 PM · positionaxismovegrabledge

move player to the grabPoint

Hello! I got a great problem with this...Making a grabPoint i got it working, but the player is a little far from grabPoint when grab the point...

I used this to get it on the right height(same of the grabPoint):

transform.position.y = collision.transform.position.y;

Ok, that is working. But Playermodel is a little far from the grabPoint in the axis Z (of the player)... Well i would do the same thing in the Z axis, but it doesnt work.Cause it is about global axis, i need local(some grabPoint would be rotated and that`s the problem)...maybe something about localPosition would help, but not with the same sintax...i tried it before...

[EDIT] I'm using this code:

function OnTriggerEnter(collision : Collider) { 
    if (collision.gameObject.tag == "grabPoint") { 
        grab=true;
        nogravity=true;
        transform.position.y = collision.transform.position.y;
        transform.position.z = collision.transform.position.z;
        transform.eulerAngles.y = collision.transform.eulerAngles.y;
    }
} 

Please help me!!!

Thank you Guys! =D

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

2 Replies

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

Answer by Loius · Oct 05, 2010 at 07:46 AM

You need to add an offset to the player's new position.

Put a GrabPoint down somewhere, and see exactly where the player should be in relation to it to be visually correct. Then put that value into the var offset : Vector3 below:

transform.position = collision.transform.InverseTransformPoint( offset );

InversetTransformPoint takes rotation into account, so as you rotate a grabPoint, it should rotate the snap-to position properly.

If different GrabPoints can have different offsets, you may need to make offset a member of GrabPoint objects rather than a global / magic number.

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 Mike 3 · Jun 16, 2010 at 06:02 PM

you could just use localPosition instead of position for things you want in local space to an object

alternatively, you could use transform.forward to get the local forward vector of a transform

Comment
Add comment · Show 2 · 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 Henrique · Jun 16, 2010 at 06:41 PM 0
Share

localPosition isn't working too. With localPosition I got greater problem than before. And transform.forward got the same old problem... It isn't working...=(

avatar image Mike 3 · Jun 16, 2010 at 07:20 PM 0
Share

it may be best to post the code you're trying then, otherwise it's just guesswork

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

No one has followed this question yet.

Related Questions

Vector 3 - move on only one axis 0 Answers

Change position of camera on scene load? 1 Answer

SmoothDamp not working? 1 Answer

Leap Motion, grab and rotate object 1 Answer

Create Animation in unity3d only on one axis 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