Advertisement
Guest User

DemoBuilding.tscn

a guest
May 10th, 2020
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. [gd_scene load_steps=7 format=2]
  2.  
  3. [sub_resource type="SpatialMaterial" id=3]
  4. albedo_color = Color( 0.0666667, 0.498039, 0.027451, 1 )
  5. roughness = 0.8
  6.  
  7. [sub_resource type="PlaneMesh" id=4]
  8. material = SubResource( 3 )
  9. size = Vector2( 50, 50 )
  10.  
  11. [sub_resource type="ConvexPolygonShape" id=5]
  12. points = PoolVector3Array( 25, 0, 25, -25, 0, 25, 25, 0, -25, -25, 0, -25 )
  13.  
  14. [sub_resource type="GDScript" id=6]
  15. script/source = "extends Spatial
  16.  
  17. onready var current_wall = $\"../Wall\".duplicate()
  18. onready var camera = $\"../Camera\"
  19.  
  20. func _ready():
  21. add_child(current_wall)
  22.  
  23. func round_to_nearest(var to_round : float, var snap : int) -> float:
  24. return snap * round(to_round / snap as float)
  25.  
  26. func _physics_process(var _delta : float):
  27. var mouse_pos = get_viewport().get_mouse_position()
  28. var from = camera.project_ray_origin(mouse_pos)
  29. var to = from + camera.project_ray_normal(mouse_pos) * 1000.0
  30. var result = get_world().direct_space_state.intersect_ray(from, to)
  31. if not result.empty():
  32. current_wall.translation = result.position
  33. current_wall.translation.y = 5
  34. current_wall.translation.x = round_to_nearest(current_wall.translation.x, 10)
  35. current_wall.translation.z = round_to_nearest(current_wall.translation.z, 10)
  36.  
  37. if Input.is_action_just_pressed(\"ui_left\"):
  38. current_wall.rotate_object_local(Vector3.UP, deg2rad(90))
  39. elif Input.is_action_just_pressed(\"ui_right\"):
  40. current_wall.rotate_object_local(Vector3.UP, deg2rad(-90))
  41.  
  42. if Input.is_action_just_pressed(\"ui_accept\"):
  43. current_wall = $\"../Wall\".duplicate()
  44. add_child(current_wall)
  45. "
  46.  
  47. [sub_resource type="SpatialMaterial" id=1]
  48. albedo_color = Color( 0.556863, 0.207843, 0.207843, 1 )
  49. roughness = 0.4
  50.  
  51. [sub_resource type="CubeMesh" id=2]
  52. material = SubResource( 1 )
  53. size = Vector3( 10, 10, 1 )
  54.  
  55. [node name="World" type="Spatial"]
  56.  
  57. [node name="Camera" type="Camera" parent="."]
  58. transform = Transform( 0.707107, 0.353553, -0.612372, 0, 0.866025, 0.5, 0.707107, -0.353553, 0.612372, -20, 15, 20 )
  59.  
  60. [node name="Floor" type="StaticBody" parent="."]
  61.  
  62. [node name="MeshInstance" type="MeshInstance" parent="Floor"]
  63. mesh = SubResource( 4 )
  64. material/0 = null
  65.  
  66. [node name="CollisionShape" type="CollisionShape" parent="Floor"]
  67. shape = SubResource( 5 )
  68.  
  69. [node name="BuildingManager" type="Spatial" parent="."]
  70. script = SubResource( 6 )
  71.  
  72. [node name="Wall" type="MeshInstance" parent="."]
  73. transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -40, 5, 0 )
  74. mesh = SubResource( 2 )
  75. material/0 = null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement