- Home /
How to move a object from A to B when the character collides with a object?
Hi. I have a spawn point where my player spawns. But I also have checkpoints, and I want that when the player collides with a checkpoint to move the checkpoint to a certain x,y,z position. I've tried to do it several times but without success. Anyone can help?
itween might help.
OnCollisionEnter() { transform.itween(pointA, pointB); }
tried it, but it didn't work (because the script or because of me) :(
Post the script so that we have a better idea of what you're trying to do.
Answer by hvilela · Oct 26, 2012 at 11:19 PM
Do you mean a teleporter?
Yes, but I don't know how to do it so that the SpawnPoint moves, not the character.
It's the same, just pass the spawn point game object ins$$anonymous$$d the character.
Answer by Piflik · Oct 27, 2012 at 05:24 PM
Add this to your checkpoint:
function OnTriggerEnter(item : Collider) {
if(item.tag == "Player")
transform.position = Vector3(x, y, z);
}
This will move the checkpoint to whatever xyz coordinates you use, when an object with the tag 'Player' enters the checkpoint's trigger.
If you want to move the checkpoint multiple times to different locations, use a public array and put empty gameobjects from the scene there via the Inspector. Instead of using a specific Vector for the new position, you use 'array[i].transform.position' and increment 'i' afterwards.
Your answer
Follow this Question
Related Questions
Updating prefab information live 2 Answers
error on moving object to end of spawned object 0 Answers
Object moves to new location in vector array 1 Answer
Born again object 1 Answer