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 /
  • Help Room /
avatar image
0
Question by drabs · Apr 21, 2016 at 04:46 AM · c#pickup

I need help with Pick Ups

I'm trying to make a feature that causes a pick up to be magnetized to the player when the player gets close enough. This would be to get rid of the annoyance of just missing the pickup by a slight amount, without having an unrealistically big hit box. How could I go about doing this?

Note: The game I'm making is programmed in C#.

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
0

Answer by Jessespike · Apr 21, 2016 at 09:30 PM

Have you tried Vector3.Distance? You can change the scale of the object when the distance falls below a value. If you want an item to grow bigger as you get closer, you can use Vector3.Lerp as well.

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 drabs · Apr 22, 2016 at 03:13 PM 0
Share

That's not what I'm going for though. I want the pickup to move towards the player when the distance between the pick up and the player falls below a certain value.

Also I'm sorry if i was unclear initially. I just realized that I typed "magnified" when I meant to say "magnetized."

avatar image
0

Answer by Soraphis · Apr 22, 2016 at 05:18 PM

@Jessespike might have missunterstood you but generally his solution would be correct:

check the players distance to all pickup-objects if the distance is smaller than X move the object a bit closer to the player (velocity can be calculated by distance (further away > slower distance)) if the distance is smaller than Y, pick it up.

to move the object closer to the player you can use Lerp, thats correct too.


instead of checking every single pickable every frame you could add a collider around the player (add it as a child gameobject). make it a trigger, set it to never sleep.

add a script to the pickables, where you use "OnTriggerStay", to check if its in the "magnetsphere" and move it a bit closer.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Pickup objects pass through other objects 0 Answers

Rolling Ball Game - How do I set it so the Player only wins, if they reach the finish line, with a certain number in Count?, 1 Answer

Help with consuming an object on key press 1 Answer

How to make a coin spin(not a 3d mesh) 1 Answer

OnCollisionEnter2D not being called 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