But how to spawn the entity on the ground??Code:[ChatCommand("chest")] private void cmdChatairbox(BasePlayer player, string command, string[] args) { string name = "assets/prefabs/misc/supply drop/supply_drop.prefab"; chest.x = 555; chest.y = 44; <---- not ground chest.z = 555; BaseEntity entity = GameManager.server.CreateEntity(name, chest); entity.Spawn(true); }
Spawn prefab on ground
Discussion in 'Rust Development' started by Rusty, Apr 4, 2016.
-
I'd say use a ray cast something along the lines with hitting this layer.
floor = UnityEngine.LayerMask.GetMask("Terrain", "World");
I'm no expert at that though -
Wulf Community Admin
There's a working example in my Hide and Seek plugin if you'd like as well.
-
@Wulf where abouts in the plugin is the working example?
-
Code:
private static LayerMask GROUND_MASKS = LayerMask.GetMask("Terrain", "World", "Construction"); //Credit: Wulf static Vector3 GetGroundPosition(Vector3 sourcePos) { RaycastHit hitInfo; if (Physics.Raycast(sourcePos, Vector3.down, out hitInfo, GROUND_MASKS)) { sourcePos.y = hitInfo.point.y; } sourcePos.y = Mathf.Max(sourcePos.y, TerrainMeta.HeightMap.GetHeight(sourcePos)); return sourcePos; }
-
Thanks!