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 Keira · Dec 05, 2010 at 03:05 PM · javascriptpickup

Unity JS - Picking up objects

Hi, I'm sure similar questions have been asked but please bare with me as I'm new!

I'm creating an FPS game and require the ability to pick up items. I've heard the use of raycasts but I'm not sure how to script this. I'm hoping to make it so that when the character is in proximity of the object, or looking at it within proximity (whichever makes more sense) from them to pick it up so it is no longer there.

Additionally to this, I want there to be objects that can be opened only if the item required has already been picked up.

Any help would be greatly appreciated!

Update:

I tried the following code but it isn't working, any ideas? (I have a box collider on the object I want to interact with)

var rayCastLength = 5;

function Update () { var hit : RaycastHit; if (Physics.Raycast(transform.position, transform.forward, hit, rayCastLength)) { if(hit.collider.gameObject.tag == "ID") { hit.collider.gameObject.Destroy(); } } }

PS.I attached that script to the Main Camera within the First Person Controller.

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
Best Answer

Answer by Justin Warner · Dec 05, 2010 at 03:13 PM

http://www.youtube.com/watch?v=7abYR8W8ji4

That's for raycasts...

I'd personally do an if statement, check the distance between the item and the player, and then do another if in that if to check if the player has it, if he does, output it to screen, if he doesn't, then have it Destroy, then put it in his inventory...

I don't know much about raycasts, so I'd wait for someone more intelligent on that to post an answer, but I hoped I steered you a little bit =).

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 Keira · Dec 05, 2010 at 03:44 PM 0
Share

You did and thank you, I'll look in to RayCasting and all the things you suggested! :)

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

Weapon Pickup and change 2 Answers

Stop Object From Ignoring Collisions - Pick Up Rigidbody 0 Answers

pickup counter and timer help 0 Answers

How to pickup and equip an object? 0 Answers

eating candy, spitting it out. 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