x


restart when dead

how can i make it so that when my player touches a collider with the tag Restart he teleports back to the start of the scene?

more ▼

asked Jun 06 '12 at 05:32 PM

artsdcs gravatar image

artsdcs
3 11 14 15

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Vector3 StartingPosition; Vector3 StartingForwardPosition;

void Start() {

StartingPosition = transform.position; StartingForwardPosition = transform.forward; }

//If its a collider, use OnCollisionEnter //If its a trigger, use OnTriggerEnter(Collider coll) void OnCollisionEnter(Collision coll) { transform.position = StartingPosition; transform.forward = StartingForwardPosition; }

more ▼

answered Jun 06 '12 at 07:32 PM

warddav16 gravatar image

warddav16
0

(comments are locked)
10|3000 characters needed characters left

To answer your question, let us consider two separate aspects of the game. The first is "position". Every game object (including your player) has a position in the 3D world. The position is given by a Vector3 which contains x, y and z values. If we assume that the start of the scene is at 0,0,0 then to "teleport" back to the start, you would execute the following code:

transform.position = Vector3(0,0,0);

It is assumed that this code is executed in the context of your player gameObject.

The next part of your question is detecting when a player collides with an object.

See the following:

http://unity3d.com/support/documentation/Components/class-BoxCollider.html

At a high level, your will flag your Collider component as a "Trigger". When your player game object enters the trigger, the OnTriggerEnter() callback on a script attached to your collided object will be called. This will serve as the indication that your player needs to be teleported back to the start of the scene using the transform.position technique described previously.

more ▼

answered Jun 06 '12 at 06:33 PM

kolban gravatar image

kolban
1.8k 2 7

is it also possible to make it so that this happens when you touch partcile colliders?

thank you

Jun 06 '12 at 06:59 PM artsdcs

Apparently the answer is yes. I searched and found:

http://answers.unity3d.com/questions/16239/particle-colliders.html

Jun 06 '12 at 08:18 PM kolban
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2056
x171
x91
x60
x3

asked: Jun 06 '12 at 05:32 PM

Seen: 530 times

Last Updated: Jun 06 '12 at 08:18 PM