我正在使用Ursina引擎创建一个3D游戏。然而,当我试图加载FirstPersonCharacter,我得到的只是一个灰色的背景(正常)和一个非常小的洋红方,在中心,在45°倾斜。那是什么?
我第一次尝试为第一人称角色制作自己的机器,根据鼠标的位置移动相机(我有这个),我在玩数学和其他的动作.我看了这段视频(https://www.youtube.com/watch?v=DHSRaVeQxIk),完全是为了别的东西,我发现了FirstPersonController。
但是,与他(几乎)相同的代码,这是行不通的!有什么问题,有人已经碰到了吗?FirstPersonController坏了吗?还是我的大脑坏了?
编辑:在ursina手册中发现,小的洋红方格是光标。但我还是不能动,不能有重力什么的?我看不见我的地板。
第二个编辑:使用ursina提供的一些代码,整理一下,我现在可以看到我的地板了。但我只能在一个轴(上下)移动相机,我不能移动,没有重力,什么都不能.
这是我的代码:
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
window.title = 'The lab'
window.borderless = False
window.fullscreen = True
window.exit_button.visible = False
window.fps_counter.enabled = True
floorcubes = []
for i in range(-20, 20, 2):
for j in range(-20, 20, 2):
floorcubes.append(Entity(model='cube', color=color.white, scale=(2,2,2), position = (i, 0, j)))
player = FirstPersonController()
app.run()以下是ursina备忘表中提供的代码,排列如下:
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
ground = Entity(model='plane', scale=(100,1,100), color=color.yellow.tint(-.2), texture='white_cube', texture_scale=(100,100), collider='box', position = (0, -2, 0), grounded = True)
e = Entity(model='cube', scale=(1,5,10), x=2, y=.01, rotation_y=45, collider='box', texture='white_cube')
e.texture_scale = (e.scale_z, e.scale_y)
e = Entity(model='cube', scale=(1,5,10), x=-2, y=.01, collider='box', texture='white_cube')
e.texture_scale = (e.scale_z, e.scale_y)
player = FirstPersonController(model='cube', y=2, origin_y=-.5, gravity = 1)
player.gun = None
gun = Button(parent=scene, model='cube', color=color.blue, origin_y=-.5, position=(3,0,3), collider='box')
gun.on_click = Sequence(Func(setattr, gun, 'parent', camera), Func(setattr, player, 'gun', gun))
gun_2 = duplicate(gun, z=7, x=8)
slope = Entity(model='cube', collider='box', position=(0,0,8), scale=6, rotation=(45,0,0), texture='brick', texture_scale=(8,8))
slope = Entity(model='cube', collider='box', position=(5,0,10), scale=6, rotation=(80,0,0), texture='brick', texture_scale=(8,8))
def input(key):
if key == 'left mouse down' and player.gun:
gun.blink(color.orange)
bullet = Entity(parent=gun, model='cube', scale=.1, color=color.black)
bullet.world_parent = scene
bullet.animate_position(bullet.position+(bullet.forward*50), curve=curve.linear, duration=1)
destroy(bullet, delay=1)
app.run()多亏了答案,我现在有:
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
import pyautogui
import random
import math
app = Ursina()
is_fullscreen = True
window.title = 'The lab'
window.borderless = False
window.fullscreen = is_fullscreen
window.exit_button.visible = False
window.fps_counter.enabled = True
latest_mouse_pos = pyautogui.position()
pyautogui.FAILSAFE = False
sensibility = 2.5
mouse.visible = True
floorcube = Entity(model="cube", color = color.white, scale=(20, 1, 20), collider="box", position=(0, -100, 0))
def update():
global latest_mouse_pos
if held_keys['f']:
camera.fov += 1
if held_keys['r']:
camera.fov -= 1
player = FirstPersonController()
app.run()发布于 2021-05-22 07:57:48
有重力,它的作用是让玩家陷入无穷大。当你移动鼠标向上看,你会看到立方体消失在远处。
解决方案是将collider='box'添加到您的地板立方体,以防止玩家通过。请注意,起始点似乎在其中一个立方体内,所以您必须跳出它(使用空格键)或稍微降低您的地板立方体的位置。
https://stackoverflow.com/questions/67588962
复制相似问题