Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. 知识库
  3. 三维积木
  4. 转动物体指向某个目标点

转动物体指向某个目标点

Scheduled Pinned Locked Moved 三维积木
1 Posts 1 Posters 920 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    介绍

    将一个新的物体(例如飞机)被添加到 3D 场景时,其默认面向方向是正 Y 方向。你可以通过以下积木指定目标点,让物体指向那个目标点的方向:

    cd05d06e-deef-4e09-9d3b-1f88e2ba33f9-image.png

     

    这个积木有 5 个输入参数:

    • X/Y/Z 位置:这是目标点的位置。
    • 用时:这是物体转到新方向所需的时间。如果为0,则物体会立即转动过去;否则,它将在这段时间内逐渐向新方向旋转。
    • 是否等待:当“用时”不为0秒时,这个参数控制该积木是否阻塞下一个积木的执行。如果为“需等待的”,那么程序将不会继续,直到物体完成旋转;否则程序将继续执行下一个积木,同时保持物体继续进行旋转。

     
     

    示例

    在这个示例程序中,我们先添加一个飞机模型,然后通过一段时长为 2 秒的动画使其指向目标点 x = 100,y = 100,z = 20。

    不.gif

     
    注意,目标位置只影响相对于物体位置的旋转方向。在上面这个例子中,如果我们使用 (10, 10, 2) 作为目标位置,我们会得到相同的旋转结果,因为物体位于 (0, 0, 0) 的位置。

     
     

    使用父节点 + 指向位置(高级)

    当我们使用“指向位置”积木时,有的时候可能得不到想要的结果,因为旋转物体的方法有很多种。

    例如,当我们旋转飞机指向 (100, 100, 100) 的位置时,飞机的机身会围绕自身“侧滚”,因此左翼会比右翼倾斜得更高:

    rr3.gif

     
    为了更好地控制物体的旋转方式,我们可以使用父节点辅助完成部分甚至全部旋转。

    例如,你可以使用一个转换器物体“t”作为飞机的父节点。然后使用“指向位置”积木让飞机慢慢抬头,并让父节点 t 绕 Z 轴向右旋转。这样 2 个机翼将处于相对水平位置。你还可以把第一个动画设置为“可继续的”,以便让两个动画同时运行:

    rr4.gif

    1 Reply Last reply
    0
    • CreatiCodeI 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
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode