What's Possible
I will share how to make the spectate player part via commands, because a usable, non-nuisance no-clipping through blocks is not (that I am aware) possible in Vanilla Minecraft Bedrock. This will not show how to use a system such as item-dropping to change the player you spectate, as you will have to do that part yourself.
Real Quick
I will be using the selector
@a[tag="viewed"]
and referring to them as viewed
for the player being watched, and
@a[tag="spectator"]
for the spectator, which I will refer to as spectator
.
Use the /tag command to apply and remove tags from entities.
Approach
You will teleport an invisible player behind the spectating player, depending on the viewed's looking position. How do we know someone's look position?
^ ^ ^
These carets each mean something. It is kinda confusing, but for this tutorial we focus on that last caret. ^ ^ ^2
refers to the block in front of where the player's head is looking, 2 blocks in front of the head. This means that if we use a negative value (i.e. ^ ^ ^-3
) we get the blocks behind the player's looking location.
(Do not confuse this with tildes ~
! They are separate, as tildes just return the block the player's legs are in.)
How
We will use /execute along with /tp. Make a repeating command block; grab a repeating command block by entering this command into your chat window:
/give @s repeating_command_block
Put this command into it:
execute @a[tag="viewed"] ~ ~ ~ tp @a[tag="spectator"] ^ ^ ^-4 false
What did we do? Well first, we used the execute command for the sole purpose of getting access to those carets (^ ^ ^
) we use for look location. We are getting the look location of the player with tag viewed
. (Remember, you can change the selector as you desire). We put -4 on the end to get the 4 blocks behind that player's look direction. You can adjust this if you want to, just use a negative number. The false
is to prevent the hazard test (you don't need to understand this).
The reason we must use a negative value is because if the spectator is in front of the viewed, the viewed wouldn't be able to place blocks, open chests, break blocks, as they would always hit the spectator!
When the Person starts Spectating
Before that person starts spectating, you need to use these commands on them, you could do this when you first give them the spectator
tag.
effect @a[tag="spectator"] invisibility 99999 255 true
Make them invisible for a while, and show no particles.
gamemode @a[tag="spectator"] a
You don't want them breaking/placing blocks, do you?
effect @a[tag="spectator"] resistance 99999 255 true
Make them immune to damage.
effect @a[tag="spectator"] effect weakness 99999 255 true
So they can't hit entities, they won't even deal any knockback or be able to break armor stands!
Also make sure they do not have a bow, armor, milk, potions etc., if you need to be sure use /clear
.
You're Ready!
Once you have a system in place for who is being viewed, spectated, and the effects are given accordingly, set the repeating command block's Needs Redstone
select box to Always Active
.
Limitations
- If the viewed looks up, the spectator will be tped underground and
although they cannot suffocate, they will be looking at dirt or whatever
block until you level your vision.
- If the spectator finds a way to block someone attacking the viewed, they could act as a human shield, this is why I like to teleport them back a fair amount, that way its harder to block PVP.