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 JimNix · Aug 08, 2011 at 03:37 AM · raycastraypickupitem

Picking Up AND Hold Onto Items using Raycasting (Bug)

Ok, going t re-edit this to more specific, my problem in a nutshell is that I have set up a ray cast to pick up an object which I can do. However, after roughly 3 seconds or so the player (fps) drops the box and I can't work out why. Set up is a typical ScreenToPoint raycast, the ray cast itself works perfectly, however if I hold the item in the air, even for perfectly still, the item drops out of the air after a few seconds, thus what could be happening. Code to lift the item, is shown below:

 hit.collider.gameObject.transform.position = ray.GetPoint(5.5f);
 hit.collider.gameObject.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); 
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 Waz · Aug 08, 2011 at 04:56 PM 0
Share

How about actually adding information, rather than just editing to try to bump. Your question has not been answered because it is too vague.

avatar image JimNix · Aug 08, 2011 at 05:31 PM 0
Share

It's a brief question, for a brief problem. I have no idea why it's happening, therefore I can only explain the problem, which is really a simple bug. I've re-edited my problem, to make it more specific to the problem at hand.

2 Replies

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

Answer by JimNix · Aug 08, 2011 at 06:03 PM

Just solved it.

 hit.collider.gameObject.transform.position = crosshair.GetPoint(4.0f);
 hit.collider.gameObject.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); 
 hit.collider.gameObject.rigidbody.velocity = new Vector3(0.0f, 0.0f, 0.0f);


Gravity was (negative y vector) accumulating or at least fighting to pull the object down, however, setting the velocity to 0 while, the object it being held stops this happening. Once the the boolean is false (i.e. GetButton, or isHoldingObject etc) gravity, being a universal force, will be re-applied to the object, and it will fall.

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
1

Answer by Waz · Aug 08, 2011 at 05:37 PM

Yes, you have a bug. It is not in the code shown in the question, therefore it is elsewhere in your code.

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 JimNix · Aug 08, 2011 at 05:41 PM 0
Share

Thank you for the reply. It's weird as the ray cast works perfectly well for all other functionality, i.e. opening doors. And the method to pick up items, and move them also works well. But only after roughly 3 seconds of picking up the item (either still or moving) does the item drop. It's like the ray is losing contact or something. However, when I hold the ray over it, to return the Object name, the name is returned constantly without a "lose of contact".

avatar image Waz · Aug 08, 2011 at 05:47 PM 0
Share

$$anonymous$$y guess is that the object is falling because you only position it in Update, not FixedUpdate, and don't adjust it's velocity.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem With Raycast Pickup Using Touch 0 Answers

Should Items spherecast 0 Answers

how do i fix this small error 2 Answers

How can I apply damage based on a grenade explosion, but test whether the objects are behind cover so they are not damaged even within the explosion radius? 2 Answers

Math - calculate position in world space from ray on infinite plane 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