#How can I change corner coorditane

2 messages · Page 1 of 1 (latest)

pliant crescent
#

I took the center of the box as its corner. I want to take the corner coordinates as (0,0,0). However, the corner appears at x= 90 and z= 90 coordinates. Where am I going wrong? What code should I write to fix this? or something else

extends Node3D

var boxes = []
var boxTemplate = preload("res://boxTemplate.tscn")

func create_box(location, scale, layer, color):
return { "location": location, "scale": scale, "layer": layer, "color": color }

func create_boxes():
var rows = 13
var columns = 13
var x = 0
var z = 0
var l = 0
var layers = 3
var colors = [Color(1, 0, 0), Color(0, 0, 1), Color(0, 1, 0)] # Kırmızı, Mavi, Yeşil

boxes.append(create_box(Vector3(x- 90 , l, z + 90), Vector3(5, 4, 10), 1, colors[1]))                                   func create_visual_box(location, scale, color):
var box = boxTemplate.instantiate() as Node3D
var mesh_instance = box.get_child(0) as MeshInstance3D  # MeshInstance3D'yi al

var mesh = BoxMesh.new()
mesh.size = scale / 200
mesh_instance.mesh = mesh  # MeshInstance3D'ye mesh'i ata
box.transform.origin = location / 200
var material = StandardMaterial3D.new()
material.albedo_color = color
mesh_instance.material_override = material  # MeshInstance3D'ye material'ı ata
add_child(box)

func _ready():
create_boxes()
for box in boxes:
create_visual_box(box["location"], box["scale"], box["color"])
print("Box at %s on layer %d with color %s" % [str(box["location"]), box["layer"], str(box["color"])])
print("--- Tüm katmanlar bitti ---")

arctic bobcat
#

I dont really get what u want, ¿do u want so a corner of the box sits at Vector3.ZERO relative to its parent?, if your box is a packed scene, u could set the offset there, using the editor and offsetting the box, if u want to do it by code, just apply the offset like position += offset where offset is the vector to offset by, it can be half the box's width and height for example.

From what I see u are creating multiple boxes, you should make sure apply the same offset to each of them.

Also, make sure to format your code using three backticks ``` before and after the code for a better understanding