Getting the size of a

Godot Version

v4.2.2.stable.official [15073afe3]

Question

I am trying to auto generate walls around an area3d to prevent movement beyond the area3d through collision checks. The parent area3d is not of a constant size, it depends on the map. I can create a wall and size it to the width or height of the map

But I am running into a problem positioning the wall. If I try to use the same formula to move the wall it only moves a little bit. But if I try something like self.scale/2 it moves it way off out of view.

image

func _ready():
	if FileAccess.file_exists(map_image):
		var material = StandardMaterial3D.new()
		var texture = load(map_image)
		material.albedo_texture = texture
		mesh.material_overlay = material
		self.scale.x = texture.get_width()/modifier
		self.scale.z = texture.get_height()/modifier
		self.position.x = shift_horizontal
		self.position.z = shift_vertical
		
		north_wall.scale.z = 1/self.scale.z

If I could get the position of the corners of my map area3d I could probably extract the values I need. But I am unsure of how to do that.

Or am I going about this all wrong? Should I be preventing movement out of the play area some other way? If so, how can I autogenerate the barrier to match the size of the map?

If you want objects to collide you have to use StaticBody3D. Area3D can only detect physic bodies and other areas, but not collide with physic bodies.

Regarding your walls:
I believe I’ve read that changing the scale can affect correct physic calculcation. But I’m not entirely sure about this.

Maybe using a box shape for the collision shape can work? Not tested!

class_name Wall
extends StaticBody3D

var collision_shape : CollisionShape3D
var box_shape : BoxShape3D

func _ready() -> void:
        var wall_size_x = texture.get_width() * modifier

	collision_shape = CollisionShape3D.new()
	add_child(collision_shape)
        # set global_position
	
	box_shape = BoxShape3D.new()
	box_shape.size = Vector3(wall_size_x, your wall height, your wall thickness or for walls aligned the z axis the length) 
	collision_shape.shape = box_shape
1 Like

I am getting the size just fine. it is the position that is frustrating me. When I look at the scale of the Map.scale.z I get 45. But when I actually test the position I want the wall it is .5. I am not sure why the scale is so different from the position.

Is it possible to get the corner points of an area3d. Or a StaticBody3d, Mesh, or CollisionShape3d?

All right, here is the puzzler. The mesh is a rectangle. When I set the wall.position.x at .5 it lines up with the right edge.

but when I set the wall.position.z to .5 it also lines up with the bottom.

Dunno how. but it seems to work.