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");
    }

87778-capture1.jpg

Animations have it set on collision play animation. Make the animation of the coin moving to the corner of your choosing

Hi,

Its very simple.

you have two different view view.

  1. One static view Cam (orthographic) for HUD or Menu Screen.
  2. Second Dynamic View Cam (orthographic or prospective) for Gameplay.

Now how to achieve it

  1. when you player collider with coin get word to screen position using Gameplay Cam method. ( Vector3 pos = GPCam.WorldToScreenPoint(<<worldPosOfCoinInGPEnvironment>>) )
  2. 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)
  3. generate few coins at that position and give tween to move it to your desired place

OK, I found the easiest solution by @Bijan

It depends on your game but here are some options:

  1. 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.

  2. 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)

  3. 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. :slight_smile:

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

@PAHeartBeat
@Farwall

public float speed = 10.0f;

void Update()
{
    transform.position = Vector3.MoveTowards(transform.position, Camera.main.ViewportToWorldPoint(new Vector3(1.1f, 0.9f, 10.0f)), speed * Time.deltaTime);
}

Whoever is reading this today:
This is a shortened and not optimized version.
This is just for idea, you can arrange it as you like.