在划痕中,我正在尝试实现这一"遵循另一个精灵"的运动,在该运动中,另一个精灵遵循了第一个精灵的运动,就像在这场比赛中一样,信仰山:
https://www.youtube.com/watch?v=fqhyhod2-ck
基本上,我正在寻找的是伪代码,这对我的划痕和JavaScript都可以帮助我。我不确定该怎么做(显然(涉及其他精灵的X和Y位置。
谢谢。
这是一些伪代码,可以使您开始。这绝对不是您的最终解决方案;您将必须处理细节,才能完全像您想要的那样获取它。祝您好运!
let trackingArrayMaxSize = 100;
let trackingArrayFollowerStart = 50;
var trackingArrayLeaderIndex = 0;
var trackingArrayFollowerIndex = 0;
var trackingArray = [ ];
// Scratch, or whatever game engine you're using, is going to call this once per frame.
// Have a look at the Scratch wiki https://en.scratch-wiki.info/wiki/Game_Loop
// to see how Scratch does it.
function update() {
////////////
// Use the array to track the current position of the main sprite.
////////////
if(trackingArray.number_of_elements < trackingArrayMaxSize) {
// If the tracking array hasn't reached the max size, then
// just keep appending our current position to it.
trackingArray.append(main_sprite_current_position)
} else {
// If we've reached the max size, then we start treating the
// array as a circular array, storing each new position in the
// next array index as normal, but wrapping back to index 0
// when we reach the end.
trackingArray[trackingArrayLeaderIndex] = main_sprite_current_position
trackingArrayLeaderIndex = (trackingArrayLeaderIndex + 1) % trackingArrayMaxSize
}
////////////
// Read back from the array to set the position of your following sprite
////////////
if(trackingArray.number_of_elements > trackingArrayFollowersStart) {
// When the array becomes full enough (experiment to decide how full),
// set your follower position to wherever the leader was, that many frames before.
//
//
// So say we start with trackingArrayMaxSize = 100 and trackingArrayFollowersStart = 50.
// At the top of this function each frame, we'll be storing the leader's positions into
// the array. When the array has 50 elements in it, we come here and set the
// follower's position to trackingArray[0] -- and up top, we'll be storing the leader's
// position to trackingArray[50].
//
// Next time through, we'll store leader to trackingArray[51], and here we'll be setting the
// follower's position to trackingArray[1]. So your follower will always be 50 frames
// behind your leader.
following_sprite_current_position = trackingArray[trackingArrayFollowerIndex]
trackingArrayFollowerIndex = (trackingArrayFollowerIndex + 1) % trackingArrayMaxSize
}
}
这种类型的问题是反向运动学之一。我创建了一个前一段时间这样做的项目。https://scratch.mit.edu/projects/250005153/
本质上,您要做的是让小组的每个连续成员都向成员移动,如果它大于一定距离。例如,这种距离就像圆的半径。这模仿了链中绳索或原子的现实生活。希望这会有所帮助!
我对javascript还不了解这种事情在刮擦中真的很容易。
指向精灵,移动(精灵的速度(步骤。完成。
如果那样行不通,转到Sprite,指向Sprite的方向,转180,移动所需距离,并为每个链接进行此操作,并且指向每个并发以下以下链接的链接其他。(换句话说,要指向该行中的最后一个方向(
这可以用多个精灵(最简单的方式(完成,变量设置临时位置和冲压,清单和冲压,或您可以使用克隆(这更复杂(。