从摄像头发射物体
-
简介
在“第一人称射击”类型的游戏中,我们需要从摄像头的角度发射子弹或箭头等物体。当你使用 第一人称视角摄像机时,这尤其有用。
本文将介绍 3 个可以帮助你做到这一点的积木。
复制摄像头方向
将物体添加到场景中时,它面向与 Y 轴相同的方向。我们可以使用以下积木使物体面向与摄像头相同的方向:

例如,让我们添加一个指向前方的盒子。每当你单击“复制摄像头方向”积木时,这个盒子都会旋转到与摄像头相同的方向:

复制摄像头位置
同样,我们也可以使用“复制摄像头位置”积木将物体移动到与摄像头相同的位置:

例如,如果我们运行“复制摄像头位置”积木,盒子将移动到与摄像头相同的位置。你不会再看到盒子了,因为现在摄像头就在那个盒子里。这时候你需要把摄像头拉远才能看到盒子。
沿当前方向移动物体
最后,要从当前位置和方向发射出该物体,我们可以使用“设置速度”积木,然后选择“定向速度”。定向速度是物体在其当前朝向方向上移动的速度。

作为演示,在下面的程序中,我们每隔 0.5 秒添加一个新盒子,并将它从摄像头的位置射出:
当我们运行程序时,新的盒子会不断射出。https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/21a646ad-f0ae-45c3-910e-aa52bc93c6dd.gif" width="500" style="border-radius: 5px; border: 1px solid #29622d;">
请注意,当我们设置其“定向速度”时,盒子不会移动到地面以下。如果你希望盒子继续向下移动,则需要为摄像头设置更高的目标点(例如 Z = 10000),让射出的盒子远离地面。这是演示项目:
https://play.creaticode.cn/projects/997b4bdbb13724d6b5c1ede2
-
I CreatiCode pinned this topic on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login