edit:player, coin ,magnet,magnet collectible 4 different game objects
when i collide with magnet collectible, magnet gameobject gets activated.it has a big collider and no mesh so it collides before player does.the idea is when it collides with coins , coins should move towards the player or even magnet would work since its position is same with players because of the attached script.
pics:
i am trying to make 3d runner game,i have read all the related threads and watched everything thats on youtube.this might sound like a cheesy problem to you but i am a beginner at coding. so my problem is that after i pickup the coin magnet i set magnet gameobject active and when it collides with gold, gold should move towards to my player. i couldnt make this work. been trying for a day and a half now.waiting for your solutions also i tried codes by putting debug.log in there and they got printed to console.seems like coins wont change their position unless you guys give it a go
i attach this to coins
public GameObject p;
private float movementSpeed= 10f;
private void Start()
{
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Magnet"))
{
transform.position = Vector3.MoveTowards(transform.position, other.transform.position, movementSpeed * Time.deltaTime);
}
}
and this to magnet
void Start()
{
transform.position = p.transform.position;
}
// Update is called once per frame
void Update()
{
transform.position = p.transform.position;
}
also tried this code for coin but it didnt work aswell
public GameObject p;
private float movementspeed= 10f;
private void Start()
{
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Magnet"))
{
transform.position =(transform.position - p.transform.position)*time.deltatime*speed;
}
}
if anything else is needed i will update the post immediatly.i am only here f5ing the page waiting for solutions. thanks