Ursina 中的 FirstPersonController 问题
Issue with FirstPersonController in Ursina
我正在使用 Ursina 引擎创建 3D 游戏。然而,当我尝试加载 FirstPersonCharacter 时,我得到的只是一个灰色背景(正常)和一个非常小的洋红色正方形,位于中心,倾斜 45°。那是什么?
我首先尝试为第一人称角色制作自己的机制,根据鼠标位置移动相机(我有这个),然后我在玩数学和运动的东西......我正在寻找在这个视频 (https://www.youtube.com/watch?v=DHSRaVeQxIk) 中,我发现了 FirstPersonController。
但是,使用与他(几乎)相同的代码,它不起作用!那是什么问题,有人已经 运行 了吗? FirstPersonController 坏了吗?还是我脑子坏了?
编辑:在 ursina 备忘单中发现洋红色倾斜的小方块是光标。但我还是不能动,不能有重力什么的?而且我看不到我的楼层。
第二次编辑:使用 ursina 备忘单提供的一些代码,ar运行ged,我现在可以看到我的地板了。但是我只能在1个轴上(上下)移动相机,我不能移动,没有重力,什么都没有...
这是我的代码:
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()
有重力,有让玩家坠入无穷大的效果。当你移动鼠标向上看时,你会看到立方体消失在远处。
解决方案是将 collider='box'
添加到您的地板立方体以阻止玩家掉落。请注意,起点似乎在其中一个立方体内部,因此您必须跳出它(使用 space 栏)或稍微降低地板立方体的位置。
我正在使用 Ursina 引擎创建 3D 游戏。然而,当我尝试加载 FirstPersonCharacter 时,我得到的只是一个灰色背景(正常)和一个非常小的洋红色正方形,位于中心,倾斜 45°。那是什么?
我首先尝试为第一人称角色制作自己的机制,根据鼠标位置移动相机(我有这个),然后我在玩数学和运动的东西......我正在寻找在这个视频 (https://www.youtube.com/watch?v=DHSRaVeQxIk) 中,我发现了 FirstPersonController。
但是,使用与他(几乎)相同的代码,它不起作用!那是什么问题,有人已经 运行 了吗? FirstPersonController 坏了吗?还是我脑子坏了?
编辑:在 ursina 备忘单中发现洋红色倾斜的小方块是光标。但我还是不能动,不能有重力什么的?而且我看不到我的楼层。
第二次编辑:使用 ursina 备忘单提供的一些代码,ar运行ged,我现在可以看到我的地板了。但是我只能在1个轴上(上下)移动相机,我不能移动,没有重力,什么都没有...
这是我的代码:
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()
有重力,有让玩家坠入无穷大的效果。当你移动鼠标向上看时,你会看到立方体消失在远处。
解决方案是将 collider='box'
添加到您的地板立方体以阻止玩家掉落。请注意,起点似乎在其中一个立方体内部,因此您必须跳出它(使用 space 栏)或稍微降低地板立方体的位置。