Comments (1)
Edit:
I changed the code, is this:
from ursina import *
import math
app = Ursina()
window.borderless = False
window.exit_button.visible = False
window.fps_counter.enabled = True
window.entity_counter.enabled = False
window.collider_counter.enabled = False
renderdistance=10
chunkSize=5
cubes = {}
terrain = Entity(model=None, collider=None)
def g(x,y,z):
cubes[(x+renderdistance, z+renderdistance, 0)] = Entity(parent=terrain, model='cube', texture='dirt', position=(x, y, z), scale=(1,5,1))
cubes[(x+renderdistance, z+renderdistance, 1)] = Entity(parent=terrain, model='cube', texture='grass_side', position=(x, y + 3, z), scale=(1.01,1,1.01))
cubes[(x+renderdistance, z+renderdistance, 2)] = Entity(parent=terrain, model='cube', texture='grass', position=(x, y + 3, z), scale=(1,1.01,1))
def getSurface(i,k):
return int((sin(i/5)+cos(k/5))*5)
for i in range(-renderdistance,renderdistance):
for k in range(-renderdistance,renderdistance):
surface=getSurface(i,k)
g(i,surface,k)
walkspeed=4
rotspeed=90
mouse_sensitivity = Vec2(100, 100)
window.color = color.rgb(0,127,255)
camera.x=0
camera.y=0
camera.z=0
camera.fov=75
def calcular_distancia(x1,y1,z1,x2,y2,z2):
return ((x1-x2)**2+(y1-y2)**2+(z1-z2)**2)**0.5
def regenerar():
for i in range(-renderdistance,renderdistance):
for k in range(-renderdistance,renderdistance):
surface=getSurface(int(i+camera.x),int(k+camera.z))
cubes[(i+renderdistance, k+renderdistance, 0)].x=int(i+camera.x)
cubes[(i+renderdistance, k+renderdistance, 0)].y=int(surface)
cubes[(i+renderdistance, k+renderdistance, 0)].z=int(k+camera.z)
cubes[(i+renderdistance, k+renderdistance, 1)].x=int(i+camera.x)
cubes[(i+renderdistance, k+renderdistance, 1)].y=int(surface+3)
cubes[(i+renderdistance, k+renderdistance, 1)].z=int(k+camera.z)
cubes[(i+renderdistance, k+renderdistance, 2)].x=int(i+camera.x)
cubes[(i+renderdistance, k+renderdistance, 2)].y=int(surface+3)
cubes[(i+renderdistance, k+renderdistance, 2)].z=int(k+camera.z)
prev_position_x=camera.x
prev_position_y=camera.y
prev_position_z=camera.z
def update():
global prev_position_x, prev_position_y, prev_position_z
if held_keys['w'] and mouse.locked == True and mouse.visible == False:
camera.position += (math.sin(math.radians(camera.rotation_y)) * time.dt * walkspeed, 0, math.cos(math.radians(camera.rotation_y)) * time.dt * walkspeed)
if held_keys['s'] and mouse.locked == True and mouse.visible == False:
camera.position -= (math.sin(math.radians(camera.rotation_y)) * time.dt * walkspeed, 0, math.cos(math.radians(camera.rotation_y)) * time.dt * walkspeed)
if held_keys['a'] and mouse.locked == True and mouse.visible == False:
camera.position -= (math.cos(math.radians(camera.rotation_y)) * time.dt * walkspeed, 0, -math.sin(math.radians(camera.rotation_y)) * time.dt * walkspeed)
if held_keys['d'] and mouse.locked == True and mouse.visible == False:
camera.position += (math.cos(math.radians(camera.rotation_y)) * time.dt * walkspeed, 0, -math.sin(math.radians(camera.rotation_y)) * time.dt * walkspeed)
if mouse.left:
mouse.locked = True
mouse.visible = False
if held_keys['escape']:
mouse.locked = False
mouse.visible = True
if mouse.locked == True and mouse.visible == False:
camera.rotation_y += mouse.velocity[0] * mouse_sensitivity[1]
camera.rotation_x -= mouse.velocity[1] * mouse_sensitivity[0]
camera.rotation_x = clamp(camera.rotation_x, -90, 90)
for i in range(0,10):
if getSurface(camera.x,camera.z) + 6 + 0.1 < camera.y:
camera.y-=0.1
else:
if getSurface(camera.x,camera.z) + 6 - 0.1 > camera.y:
camera.y+=0.1
if calcular_distancia(prev_position_x,0,prev_position_z,camera.x,0,camera.z)>chunkSize:
regenerar()
prev_position_x=camera.x
prev_position_y=camera.y
prev_position_z=camera.z
app.run()
from ursina.
Related Issues (20)
- ERROR: Cannot install ursina==0.2, ursina==0.3..........ursina==6.1.1 and ursina==6.1.2 because these package versions have conflicting dependencies. HOT 2
- macOS missing dependency: ModuleNotFoundError: No module named 'screeninfo' HOT 3
- I used 'parent=terrain' and it didnt still worked for me for increase the performance: HOT 1
- Typo on documentation Entity Basics - Other Magic Functions HOT 2
- InputField should have a "wrap text" option
- Ursina cannot open monitor under Docker
- Graphics issues when converting to .exe HOT 2
- Ursina Build too little info HOT 1
- i am getting this error while adding the code snippet for inventory to my game. can someone explain it? HOT 4
- Loading issue for settings.py HOT 3
- Using more than one boxcast in a single update breaks some of the boxcasts. HOT 2
- Feature - allow the Audio class to allow .mp3 files. HOT 1
- Remove all entities HOT 1
- RTL language support (Persian/Farsi)
- Can't use pyinstaller to ursina HOT 4
- how to load multi textures for one model HOT 1
- Cannot build to exe because of module not found error HOT 2
- how to optimize gaem
- FirstPersonController sees through entities because of shaders HOT 2
- turn string to Vec3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ursina.