A-Frame Kinematic-body camera height problem

久未见 提交于 2020-03-25 16:06:26

问题


I have a problem where I need my camera to be a Kinematic-body and collide with wall elements however I cannot get it to stay at a fixed y-axis height of 1.6. I need a way to keep the camer a this height while maintaining its kinematic-body attribute because I need wall collisions to work. I have attached the code which I have been stuck on so far.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://aframe.io/releases/1.0.3/aframe.min.js"></script>
    <script src="//cdn.rawgit.com/donmccurdy/aframe-physics-system/v4.0.1/dist/aframe-physics-system.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/donmccurdy/aframe-extras@v6.1.0/dist/aframe-extras.min.js"></script>
    <script src="https://rawgit.com/rdub80/aframe-gui/master/dist/aframe-gui.min.js"></script> <!--GUI Library-->
    <script src="https://unpkg.com/aframe-environment-component@1.1.0/dist/aframe-environment-component.min.js"></script> <!--Environment extension-->
    <title>Courtyard and Entrance Scene</title>

</head>
<body>
    <a-scene physics="debug: true">
        
            <a-entity id="camera" position="0 1.6 0" camera look-controls wasd-controls="acceleration: 400" kinematic-body>
                <a-cursor></a-cursor>
                <a-gui-label 
                        id="playerLocation"
                        width="1" height="0.2"
                        font-size="4.5rem"
                        padding="1rem 2rem"
                        position="2 1.5 -2"
                        value="gui label"
                >
                </a-gui-label>
            </a-entity>
            
            <!-- Floor -->
            <a-plane static-body material="color: grey" width="15" height="15" rotation="-90 0 0" position="0 0 0"></a-plane>
            
            <a-box width="10" height="5" depth="0.5" static-body material="color: red" position="0 0 -5"></a-box>
            
    </a-scene>
</body>
</html>

Any insight into this problem would be greaty appreciated!


回答1:


The offsets are calculated properly when a rig is used:

<a-entity id="rig" movement-controls kinematic-body>
    <a-entity id="camera" camera position="0 1.6 0" look-controls></a-entity>
</a-entity>

Check it out in this fiddle.



来源:https://stackoverflow.com/questions/60555742/a-frame-kinematic-body-camera-height-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!