x


Spawning above the terrain

For my multiplayer game, I want random spawning. This is what I'm using:

Network.Instantiate (Player, Vector3 (Random.Range (5, 95), transform.position.y+4, Random.Range (5, 95)), transform.rotation);

It doesn't work, but it isn't what I want anyway. How could I make it so that it always spawns a bit above the ground (on the y axis)?

more ▼

asked Jun 11 '11 at 04:48 AM

Max 4 gravatar image

Max 4
254 60 64 71

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

1 answer: sort voted first

first do a raycast toward ground and find it's position and then spawn a litle bit above it. it depends on the pivot of your object too. you should calculate the distance between pivote and bottom of your object and then position it based on that. procedural object placement is a really fun topic.

more ▼

answered Jun 11 '11 at 05:01 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

Hmm, the object isn't in any particular place. The spawner is just an empty GameObject.

Jun 11 '11 at 05:04 AM Max 4
(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:

x1678
x1478
x573
x68

asked: Jun 11 '11 at 04:48 AM

Seen: 1004 times

Last Updated: Jun 11 '11 at 05:04 AM