ursina_tutorials icon indicating copy to clipboard operation
ursina_tutorials copied to clipboard

This is my code pls it's doesn't added block and I can't move the first person controller screen

Open OlliWilliam opened this issue 3 years ago • 4 comments

Main: from ursina import * from ursina.prefabs.first_person_controller import FirstPersonController from MeshCraft import MeshTerrainClass app = Ursina() window.color = color.rgb(200,0,255) subject = FirstPersonController() terrain = MeshTerrainClass def update(): pass terrain.MeshTerrain() app.run()

MeshTerrainClass: from random import randrange from ursina import * class MeshTerrain: def init(this): this.block = load_model('block.obj') this.textureAtlas = ('texture_atlas_3.png') this.subsets = [] this.numSubsets = 1 this.subWidth = 32 for i in range(0,this.numSubsets): e = Entity(model=Mesh(), texture=this.textureAtlas) e.texture_scale*=64/e.texture.width this.subsets.append(e) def genBlock(this,x,y,z): model = this.subsets[0].model model.vertices.extend([Vec3(x,y,z) + v for v in this.block.vectices]) #the texture atlas co-ord for grass uu = 8 uv = 7 model.uvs.extend([Vec2(uu,uv) + u for u in this.block.uvs]) def genTerrain(this): x = 0 z = 0 y = randrange(-1,1) d = int(this.subWidth*0.5) for k in range(-d,d): for j in range(-d,d): this.genBlock(x+k,y,z+j)

OlliWilliam avatar Jan 03 '23 12:01 OlliWilliam

Hi buddy -- very sorry for the slow reply. Try the following first:

this.block = load_model('block.obj')

Needs to be replaced with:

this.block = load_model('block.obj',use_deepcopy=True)

The use_deepcopy parameter is needed in the newer version of ursina.

Also, your init() function ought to feature double underscores like so:

def __init__(this):

Best of luck,

Red Hen

RedHenDev avatar Jan 04 '23 16:01 RedHenDev

After that, in main.py, you need to replace

terrain = MeshTerrainClass

with

terrain = MeshTerrainClass()

  • The only difference is the brackets.

Finally, further down in main.py, you need to replace

terrain.MeshTerrain()

with

terrain.genTerrain()

That is, to actually call the function that will generated your terrain.

I'll keep my fingers crossed. They'll probably be a few more bugs we haven't spotted :)

RedHenDev avatar Jan 04 '23 16:01 RedHenDev

It's still have an error is 'module' object is not callable line 7, in terrain = MeshTerrainClass() TypeError: 'module' object is not callable

OlliWilliam avatar Jan 05 '23 13:01 OlliWilliam

Looks like 'MeshCraft' can't be found. Make sure your python file (i.e. that contains your MeshTerrainClass class) is called exactly this: MeshCraft.py (since that is how you reference it via the import).

RedHenDev avatar Jan 05 '23 22:01 RedHenDev