其他分享
首页 > 其他分享> > ursina全解析-3

ursina全解析-3

作者:互联网

ursina全解析-3

前言

这篇文章简陋了点,因为这个实在太简单了

开始

今天讲第一人称操作,灰常简单
使用FirstPersonController,需要从ursina.prefabs.first_person_controller引用,可以直接看cheat sheet,所有参数都很重要
示例程序就用官方的例子,但是官方的例子有些问题,我在下面的代码里已经修改了

ffrom ursina.prefabs.first_person_controller import FirstPersonController
from ursina import *
app = Ursina()

ground = Entity(model='plane', scale=(100,1,100), color=color.yellow.tint(-.2), texture='white_cube', texture_scale=(100,100), collider='box')
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')
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()

效果视频太大,没法放,实在抱歉

标签:cube,color,gun,texture,scale,ursina,model,解析
来源: https://blog.csdn.net/weixin_42954615/article/details/117172211