• 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
Question by tonyjoseph456 · Dec 11, 2014 at 12:41 PM · collectcollectible-game-objectsmeter

How to show the effect when the coins are collected moves to the coin meter?

I would like to know how to create the effect which is in the temple run game in whihc when the coins are collected, the coins flies towards the coin meter. Is it just using a texture or using a 3d model for this purpose? Can some one please help me out? In my game, which is an infinite runner type game, the player collects coins and it is showing in the coin meter. But I want to show that the coins collected are moving to the coin meter to the player. How can it be shown? Some one please guide me regarding this topic. Thanks in advance.

Comment

People who like this

0 Show 1
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 sundhar_unity · Aug 20, 2020 at 09:25 AM 0
Share

Hope this will help, I think this is the exact thing you are asking for: https://www.youtube.com/watch?v=GgNLr7SSh1I&t=107s

3 Replies

  • Sort: 
avatar image
Best Answer

Answer by blueLED · Dec 12, 2014 at 08:48 AM

Make a coin-shaped cylinder and attach this script to it:

 using UnityEngine;
 using System.Collections;
 
 public class flyToMeter : MonoBehaviour {
 
     public GameObject meter;
     
     void Update () {
     
         transform.position = Vector3.Lerp(transform.position, meter.transform.position, 1.5f * Time.deltaTime);
 
     }
 }

Then, in your scene, make a cube, or empty game object and position it roughly where the meter is and then set that as the "meter" in the coin's inspector. Press play, the coin will fly to the meter.

Comment
muridrifai
spooneystone

People who like this

2 Show 7 · 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 NoseKills · Dec 12, 2014 at 09:07 AM 0
Share

This works for getting a nice eased-out movement effect, although I cringe every time I see Time.deltaTime as the parameter in an iterative Lerp movement :)

avatar image blueLED · Dec 12, 2014 at 09:13 AM 0
Share

Is Time.deltaTime not the right way? I thought that was SOP.

avatar image NoseKills · Dec 12, 2014 at 09:31 AM 0
Share

Lerp(A, B, t) basically moves from A towards B by t percent.

If you assume your framerate is 10 (deltaTime 0.1) you are always moving from current position to target position by 10%. So first update takes you to 90%, next 81% next 73% ... You will never get to exactly B because the distance gets basically multiplied by 0.9 every Update(), but you will make a nice easing effect where the object moves faster in the beginning and slows down as it gets nearer to target.

You should use deltaTime to get smooth movement, but in a way where you make sure that it hits 1 at some point. Typically this would mean something like storing the start and end points of the intended Lerp when the movement starts, then incrementing a public float incrementingTime in Update by deltaTime, and then Lerping with that until incrementingTime hits 1:

 transform.position = Vector3.Lerp(originalStartVector3, targetV3, incrementingTime);
 

But that's totally outside the scope of this question :D and what you proposed actually makes for a nicer look an feel for the game the OP is making.

avatar image tonyjoseph456 · Dec 12, 2014 at 09:33 AM 0
Share

Instead of moving it from coins vector 3 position, I want it to be moved from the players transform.position.

avatar image blueLED · Dec 12, 2014 at 10:54 AM 0
Share

@NoseKills Thanks for the explanation

@tony Yeah, so if you want it to go from the player position, then just make it equal to the player position first, then move to the meter.

Show more comments
avatar image

Answer by IcyHammer · Dec 11, 2014 at 04:08 PM

The easiest way to do it, is to calculate the point of your coin meter label in world space by using Camera.ScreenToWorldPoint. Then you can animate you coin for example by rotating it around its Y axis and at the same time scaling it down to appropriate size and moving it towards that calculated point.

Comment
DarylB
Jbrandan

People who like this

2 Show 3 · 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 tonyjoseph456 · Dec 12, 2014 at 03:43 AM 0
Share

So for that purpose would I need a 3d model of the coin or just the texture image of the coin.

avatar image tonyjoseph456 · Dec 12, 2014 at 04:03 AM 0
Share

can you please explain me a little more...

avatar image IcyHammer · Dec 12, 2014 at 07:54 PM 0
Share

Yes, in order for this method to work, you would need a 3d model of a coin and a texture.

avatar image

Answer by sundhar_unity · Aug 19, 2020 at 05:05 PM

Hope this will help, I think this is the exact thing you are asking for: https://www.youtube.com/watch?v=GgNLr7SSh1I&t=107s

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Bug with Enemy and Collecting 0 Answers

Pixel-to-meter camera 1 Answer

Collecting 2 items at a time by mistake. 0 Answers

Speed = 11 meters /s plane is 110 meters should take me 10 seconds but it dosn't 0 Answers

how can i collect items that fills up a GUI?? 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