how can i convert a transform into a float.

I am trying to take the current position of something once when collided and im not sure how to
do that could anyone help me out please?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CircleMover : MonoBehaviour
    public float speed = 10.0f;

    public Transform playerLocation;
    public float redirectSpeed;
    public bool isCurrentlyColliding;
    Vector3 playerposition;

    private Rigidbody2D rb;
    private Vector2 screenBounds;
    // Start is called before the first frame update
    void Start()
        rb = gameObject.GetComponent<Rigidbody2D>();
        rb.velocity = new Vector2(-speed, 0);
        screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));

    // Update is called once per frame
    void Update()
        //if (transform.position.x < -11.6f)
        //    Destroy(this.gameObject);

        if (isCurrentlyColliding)
            transform.position = Vector2.MoveTowards(transform.position, playerposition.transform.position, redirectSpeed * Time.deltaTime);

    void OnTriggerEnter2D(Collider2D other)

        if (other.CompareTag("CopyCat")) 
            playerposition = (playerLocation.transform.position);
            isCurrentlyColliding = true;

Again… I told you in comment, and you ask again to Ylin…

Learn the Basics by your own, look for tutorials… Commence with simple things… You can not start a house building the roof… Unity Answers is not a Classroom for learning from 0. Is where you come to ask specyfic things that can not be laearned in a tutorial for its dificulty or specyfic issue…

As I said, you can not come to “ask how to make simple concrete in a Superstructure construction forum”…

You just need to store it transform.position in the moent of the collision… The answer is really simple and stupid. But then you can not ask “How to store a position” because there is when we say to you, go LEARN THE BASICS.


What are the guidelines for writing good questions?

We want Unity Answers to become a comprehensive database of questions and answers related to Unity. When you ask your questions, it can be helpful to keep a few things in mind:

Some reasons for getting a post rejected:

There exists duplicate questions with answers if you were to do a search, either on Answers or on the Forum or on Unity's tutorials

Your question isn't specific enough: asking for a script, asking multiple questions in one post or asking a question that could be either subjective or require extensive discussion

Your question is about very basic issues, that can be learned just by searching in google or in multiple basic tutorials for begginers


Hey man, to save a position of an gameobject, you need a Vector2 or Vector3 instead of a float.

@YilinYang basically when my object colides with something it moves towards a diferent object but i dont want it to follow it constantly i want it to get the position of that 1 object only once it has collided.