Multimesh has StaticBody and CollisionBody. I have this script on my Multimesh that makes an array of objects in a row. (Fence for example)
tool extends MultiMeshInstance export (float) var distance:float = 1.0 setget set_distance export (int) var count:int = 1 setget set_count export (Mesh) var mesh:Mesh setget set_mesh export (Vector3) var rotMesh:Vector3 setget set_rotMesh export (Vector3) var sclMesh:Vector3 setget set_sclMesh export (Vector3) var colMesh:Vector3 onready var coll = get_node("static/collision") func set_distance(new_distance): distance = new_distance update() func set_count(new_count): count = new_count update() func set_mesh(new_mesh): mesh = new_mesh update() func set_rotMesh(new_rot): rotMesh = new_rot update() func set_sclMesh(new_scl): sclMesh = new_scl update() func update(): self.multimesh = MultiMesh.new() self.multimesh.transform_format = MultiMesh.TRANSFORM_3D self.multimesh.instance_count = count self.multimesh.visible_instance_count = count self.multimesh.mesh = mesh var offset = Vector3(0,0,0) var trfMesh:Basis = Basis(rotMesh) var extents = Vector3(colMesh.x*distance*count,colMesh.y,colMesh.z) var shape:Shape = BoxShape.new() shape.extents = extents coll.Shape = shape # or coll.shape the same error trfMesh = trfMesh.scaled(sclMesh) for i in range(count): self.multimesh.set_instance_transform(i, Transform(trfMesh, offset)) offset.x += distance
I want to set CollisionShape automatically, or at least by some params through my script.
When I trying to set CollisionShape, I get:
res://scene/test.gd:40 - Invalid set index 'Shape' (on base: 'Nil') with value of type 'BoxShape'.
https://stackoverflow.com/questions/66945513/how-to-make-multimesh-construction-script-for-godot April 05, 2021 at 04:19AM
没有评论:
发表评论