- Home /
How do you move an object through script
hello, I have a 2D game that I want it to have a CheckPoint function where when a player enters the checkpoint(this works)
if(col.CompareTag("Checkpoint")
{
Debug.Log("CheckPoint");
}
it then moves the SpawnPoint to where the CheckPoint is. which is the position of the CheckPoint which is(494.21, -8.413, 0)
To make things simpler and understandable I just want to transform the spawnpoint with that position (494.21, -8.413, 0) ill take care of the if statements.
I don't understand why can't you do this simply with the transform.position attribute ...
You are dealing with collisions and can't set the position of a transform ? o.O
Answer by Neilos · Jun 23, 2015 at 01:09 PM
If you have a reference to the GameObject of the spawn in the script then you can just position it using:
spawnObject.transform.position = new Vecvor3(x,y,0);
see the docs here.
It doesnt work the
PlayerSpawnPoint.transform.position = new Vector3(494.21, -8.413,0);
doesn't work. it has an error of "The best overloaded method match for 'UnityEngine.Vector3(float,float,float)' has some invalid arguments"
and another error "error CS1503: Arguments '#1' cannot convert 'double' expression to type 'float' "
ah no worries..thanks for the answers. i just needed to put an "f" on each numbers.
Your answer
![](https://koobas.hobune.stream/wayback/20220613201309im_/https://answers.unity.com/themes/thub/images/avi.jpg)