mesh – Rotation inside MeshInstance3D floor airplane

[ad_1]

I am making an attempt to make a illustration of a airplane that rotates round a gap in a MeshInstance3D.

To date I’ve managed to make the circle’s gap, however I am unable to make the airplane rotate across the gap. (The opening cannot rotate, simply the airplane)

Here’s what I’ve now:



extends MeshInstance3D

@export var xSize = 20
@export var zSize = 20

@export var replace = false
@export var clear_vert_vis = false
var velocity = 0.001

# Referred to as when the node enters the scene tree for the primary time.
func _ready():
    #generate_terrain(velocity : float)
    cross # Exchange with perform physique.

func generate_terrain(velocity : float):
    var a_mesh: ArrayMesh
    var surftool = SurfaceTool.new()
    
    var n = FastNoiseLite.new()
    
    n.noise_type = FastNoiseLite.TYPE_PERLIN
    n.frequency = 0.1 * velocity
    
    
    
    surftool.start(Mesh.PRIMITIVE_TRIANGLES)
    
    
    
    for z in vary(zSize +1):
        for x in vary(xSize+1):
            var y_variation = cos(velocity)
            var y = 0 #n.get_noise_2d(x*0.5,z*0.5) * 4* y_variation
            
            if inside_circle(xSize/2,x, z, 4):
                y = velocity * -1
                cross
            
            # Place in middle 0, 0
            var x1 = x -xSize/2
            var z1 = z -zSize/2
            # tying to make the rotation, however it's on improper axis
            var xNew = x1 * cos(velocity) - z1 * sin(velocity)
            var zNew = x1 * sin(velocity) - z1 * cos(velocity)
            
            # uv
            var uv = Vector2()
            
            uv.x = inverse_lerp(0,xSize, xNew)
            uv.y = inverse_lerp(0, zSize, zNew)
            surftool.set_uv(uv)
            
            # vertex
            surftool.add_vertex(Vector3(xNew,y,zNew))
            
    
    var vert = 0
    for z in zSize:
        for x in xSize:
            surftool.add_index(vert+0)
            surftool.add_index(vert+1)
            surftool.add_index(vert+xSize+1)
            
            surftool.add_index(vert+xSize+1)
            surftool.add_index(vert+1)
            surftool.add_index(vert+xSize+2)
            vert += 1
        vert += 1
    
    surftool.generate_normals()
    
    a_mesh = surftool.commit()
    
    mesh = a_mesh
    
    
    
    cross

# return the circle across the airplane
func inside_circle(middle: float, x: float, z: float, radius : float):
    var dx = middle - x
    var dz = middle - z
    var distance_squared = dx * dx + dz * dz
    return distance_squared <= radius * radius


# Referred to as each body. 'delta' is the elapsed time because the earlier body.
func _process(delta):
    velocity += 0.001264
    generate_terrain(velocity)
        
    if clear_vert_vis:
        for i in get_children():
            i.free()
    cross



How can I make this airplane rotate across the gap, with out the outlet rotating?

This image is before I try to apply rotation

[ad_2]

Categories:

Leave a Reply

Your email address will not be published. Required fields are marked *