Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RVDL_IT · May 15, 2017 at 03:04 PM · c#vector3quaternionaddmultiply

Vector3 and Quaternion issues.

For some reason my quaternions and vector3s for my picking up and holding items script aern't working. Would you guys please be so kind as to help me with fixing this?

My declarations:

 private Vector3 CharVec;
 private Vector3 KnifeVec;
 private Vector3 CleaverVec;
 private Vector3 BreadKnifeVec;
         
 private Quaternion CharQua;
 private Quaternion KnifeQua;
 private Quaternion CleaverQua;
 private Quaternion BreadKnifeQua;

My values:

 CharVec = Character.transform.position;
 KnifeVec = new Vector3(1.68f, 3.05f, 2.12f);
 CleaverVec = new Vector3(1.68f, 2.61f, 1.95f);
 BreadKnifeVec = new Vector3(1.59f, 2.62f, 1.90f);
             
 CharQua = Character.transform.rotation;
 KnifeQua = new Quaternion(13.80f, -23.77f, -81.62f, 1f);
 CleaverQua = new Quaternion(17.86f, -42.52f, -92.53f, 1f);
 BreadKnifeQua = new Quaternion(-17.16f, 167.89f, 90.24f, 1f);

And my usages:

 if(CarryableObject.name == "knife"){
     CarryableObject.transform.rotation = CharQua * KnifeQua;
     CarryableObject.transform.position = CharVec + KnifeVec;
 }
 if(CarryableObject.name == "cleaver"){
         CarryableObject.transform.rotation = CharQua * CleaverQua;
         CarryableObject.transform.position = CharVec + CleaverVec;
 }
 if(CarryableObject.name == "bread knife"){
     CarryableObject.transform.rotation = CharQua * BreadKnifeQua;
     CarryableObject.transform.position = CharVec + BreadKnifeVec;
 }
Comment
Add comment · Show 2
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 RobAnthem · May 15, 2017 at 03:53 PM 1
Share

Why aren't you just using some sort of universal hand slot?

You basically place an empty GameObject childed to the players hand, then set the equipped weapons to the objects position and rotation.

You may also need to place your weapons inside empty GameObjects so that their standard 0,0,0 position is actually where the Hand;e would be sitting in the proper position of the hand slot.

Also if you are childing these objects to anything at all, then position and rotation no longer work as intended, you must use localPosition and localRotation so that they are only altered to their new world space and not independently.

avatar image tanoshimi RobAnthem · May 15, 2017 at 04:47 PM 1
Share

Yeah - my gut feeling is that this could all be completely replaced with:

 CarryableObject.transform.SetParent(Character.transform);

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by leech54 · May 18, 2017 at 11:03 AM

Quaternions are values between -1.0 and 1.0 it looks like you are trying to give it euler angles. I think the fix might be Quaternion.Euler(...).

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 Trevdevs · May 15, 2017 at 05:22 PM

From what I understand your trying to make a script that places an item in your hand and you want to pick it up from the ground? I assume here is a simple script that does that. I have not tested if this works there may be some syntax errors I did this completly without auto completion and on notepad++ I will test it and edit it when I am home if it doesn't work. I did this in 10 minutes so its not perfect but should give you an idea at least.

My script should picks up any item when you left click while looking at it and overrides what it in your hand if you try picking up a new item;

 public class PickupItem : MonoBehaviour
 {
     public Transform hand; //The location of the hand, could use Vector3 instead of Transform but I like doing it this way.
     
     public GameObject itemInHand; //A nice reference to the item you picked up.
     
     void Update()
     {
         //What I'm gonna do is draw a raycast from the middle of the screen aka when you look at an object. and if you click while looking it will pick up the object.
         RaycastHit hit;
         Ray ray = Camera.main.ViewportPointToRay (Vector3(0.5f, 0.5f, 0));
         
         if(Physics.Raycast(ray, out hit)
         {
             if(Input.GetMouseButtonDown(0))
             {
                 Debug.Log(hit.collider.transform.name);
                 if(hit.collider.tag == "Item"); //MAKE SURE TO NOW TAG any items you want to pickup with a new tag called Item <---- I forgot to do this a lot.
                 {
                     if(itemInHand == null) //if no item is in hand pickup what your looking at.
                     {
                         hit.collider.transform.SetParent(hand);
                         itemInHand = hit.collider.transform.gameObject;
                         itemInHand.position = Vector3.zero;
                 }
                 else //if an item is in the hand
                 {
                     hand.DetachChildren();
                     
                     hit.collider.transform.SetParent(hand);
                     itemInHand = hit.collider.transform.gameObject;
                     itemInHand.position = Vector3.zero;
                 }
             }
         }
     }
 }


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 16, 2017 at 10:18 AM 0
Share

You probably want to set the localPosition to zero and not the world position of the object. At the moment you move the item to the world origin.

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

322 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add 2 Quaternions. 2 Answers

calculating looking angle between 2 transforms 0 Answers

Rotate player (rigidbody) towards his movement 2 Answers

Pose.ctor - create pose from vector3 and quaternion 1 Answer

Slerp look at direction not working... 3 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