- Home /
How to move all coin to corner after pickup which looks like coin is moving from 3d space to 2d canvas corner position.
Hi,
I am trying to make a game like temple run 2. I want the same effect as stated in question and as attached screenshot. I tried with Animation its working when I animate the coin to center top but no luck with top left corner. Please Help. Thanks
Here is code:
if (col.gameObject.tag == "500") {
score = CryptograpicEncryption.GetInt("ScoreKey") + pick500;
CryptograpicEncryption.SetInt ("ScoreKey", score);
ScoreCount.text = "Cash Collected: " + CryptograpicEncryption.GetInt("ScoreKey").ToString ();
col.gameObject.GetComponent<Animator> ().SetTrigger ("openNote");
col.gameObject.transform.GetChild (1).GetChild (1).gameObject.SetActive (false);
col.gameObject.GetComponent<Animator> ().SetTrigger ("highLeft");
}
Answer by Farwall · Feb 14, 2017 at 06:38 AM
OK, I found the easiest solution by @Bijan
It depends on your game but here are some options:
Add an empty gameobject to your character and carefully set its position so that it always be positioned behind the desired ui object. Then move the coins from 3d space into the 3d space position of the game object.
Remove the coin as soon as the player get it, then create an identical coin using UI.Image in its place (in 2d space of canvas) immediately moving to the corner of canvas. You can convert 3d space position to 2d using 2dPosition = Camera.main.WorldToScreenPoint(3dPosition)
You can calculate the 3d position of the corner of the canvas using 3dPosition = Camera.main.ScreenToWorldPoint(2dPosition) and make the coins follow that location. But the location changes overtime as the camera moves so you should recalculate it every frame.
I chose #2 and working great. :)
Answer by Pitiedowl · Feb 10, 2017 at 07:27 PM
Animations have it set on collision play animation. Make the animation of the coin moving to the corner of your choosing
Answer by PAHeartBeat · Feb 11, 2017 at 11:14 AM
Hi,
Its very simple.
you have two different view view.
One static view Cam (orthographic) for HUD or Menu Screen.
Second Dynamic View Cam (orthographic or prospective) for Gameplay.
Now how to achieve it
when you player collider with coin get word to screen position using Gameplay Cam method. (
Vector3 pos = GPCam.WorldToScreenPoint(<<worldPosOfCoinInGPEnvironment>>)
)use the screen position get world position of to place animation coin. use HUD cam to get world position from screen pos.
pos = HUDCam.ScreenToWorldPoint(pos)
generate few coins at that position and give tween to move it to your desired place
Answer by LostShepherd · Dec 31, 2021 at 06:47 PM
Hi,
Sry am resurrecting this thread here.
I am a newbie building a 2D game for mobile and I have been following this thread, I've been able to manage most things myself until now but this is beating me.
I have two cameras setup as per the attached screen shots.
I have been trying to implement a similar effect in my case an object collision, which creates a scoretext in the UI layer, that then travels to my UI score counter in the top RHS of my screen. Effectively option 2 from above although I trigger based off a scoring collision.
I had been attempting to do this by grabbing the position of the gameplay object at the point of impact, converting the transform position to a screen point via the Gameplay (MainCamera) e.g.
//On collision
Vector3 pos = GameManager.GMInstance.GetMainCamera().WorldToScreenPoint(gameObject.transform.position);
Then I was getting a pooled UI text object, enabling it and setting the text value, color and most importantly position based on pos, the pooled items are parented to my Canvas transform. Eventually I wanted to DoTween it to the score counter, but I have not been able to get that far.
I think a big part of the issue is that the initial pool creates objects which are scaled very high e.g. 38.876% with exaggerated coordinates e.g. Vector3(-388.999939,-1320.547,-3683.23853). I think this might be the point where the UI Camera lives, I am not sure if this is because I have the pooling script attached to a UI panel in the canvas?
I could be going about this all wrong I'm not sure, but I've tried a few things and not had much luck. I'm not sure if that is the best way to pool UI elements i.e. attached to the canvas, but as I could have up to 100 items repeatedly colliding on screen I do not want to create and destroy UI elements.
Any advice or ideas as to why I am not cracking this would be much appreciated.
Thanks, LS
Your answer
![](https://koobas.hobune.stream/wayback/20220612110756im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Rewarded ads don't give rewards 0 Answers
Need help with using Player Prefs to save number of coins collected. 1 Answer