Teleportation: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Ozzypig
Less tutorial, more about teleportation and the effects that can be applied
>Quenty
No edit summary
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{CatUp|Tutorials}}
''This article is about moving parts around inside a single Roblox game. For the Roblox teleport service, See [[TeleportService| Teleport Service]].''{{CatUp|Tutorials}}
 
 
__TOC__
__TOC__


Line 18: Line 20:
One can teleport all players in the game by iterating over each one of their Characters and setting the CFrame accordingly. However, you should be careful and offset the target positions so that the players' torsos do not overlap.
One can teleport all players in the game by iterating over each one of their Characters and setting the CFrame accordingly. However, you should be careful and offset the target positions so that the players' torsos do not overlap.
<pre>
<pre>
target = Vector3.new(0, 50, 0) --could be near a brick or in a new area
target = CFrame.new(0, 50, 0) --could be near a brick or in a new area
for i, v in pairs(game.Players:GetChildren()) do
for i, player in ipairs(game.Players:GetChildren()) do
v.Character.Torso.CFrame = CFrame.new(target + Vector3.new(0, i * 5, 0)) --add an offset of 5 for each character
player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
--add an offset of 5 for each character
end
end
</pre>
</pre>
Line 26: Line 29:


== Teleportation Effects ==
== Teleportation Effects ==
You can add in fading effects by using '''for-loops''' to set the Transparency of your limbs.
You can add in fading effects by using [http://wiki.roblox.com/index.php/Loop#The_.27for.27_Statement for loops] to set the Transparency of your limbs.
<pre>
<pre>
player = game.Players.Player --you might want to change this...
player = game.Players.Player --you might want to change this...
Line 32: Line 35:


function fadeTo(a, b, c)
function fadeTo(a, b, c)
for i=a, b, c do --go from a to b, counting by c
for transparency = a, b, c do
for j, v in pairs(player.Character:GetChildren()) do --for each of the objects in the character,
--go from a to b, counting by c
if v:IsA("Part") then --check if it's a part, and if so
 
v.Transparency = i --set it's transparency
for _, part in pairs(player.Character:GetChildren()) do
end
--for each of the objects in the character,
end
 
wait(0.1)
if part:IsA("BasePart") then
end
--check if it's a part, and if so
 
part.Transparency = transparency
--set its transparency
end
end
wait(0.1)
end
end
end


fadeTo(0, 1, 0.1) --fade out,
fadeTo(0, 1, 0.1) --fade out,
player.Character.Torso.CFrame = CFrame.new(target) --teleport the player
player.Character.Torso.CFrame = target --teleport the player
fadeTo(1, 0, -0.1) --fade back in
fadeTo(1, 0, -0.1) --fade back in
</pre>
</pre>

Latest revision as of 23:41, 26 April 2012

This article is about moving parts around inside a single Roblox game. For the Roblox teleport service, See Teleport Service.


Introduction

Teleportation is a term given to the act of moving a group of Parts (most of the time, a player's character) to a certain coordinates. In ROBLOX, setting the Position property of Parts would disconnect the Part from any other connected Parts and break the model. Therefore, one cannot use the following to teleport a player because it would disconnect the Torso from the Head.

game.Workspace.Player.Torso.Position = Vector3.new(0, 50, 0)

To correctly teleport a player without killing them, you must use the CFrame property and use the CFrame data type instead.

game.Workspace.Player.Torso.CFrame = CFrame.new(Vector3.new(0, 50, 0))

CFrame versus MoveTo

MoveTo can be used in place of setting the CFrame of one brick in the model. MoveTo will only change the Position/CFrame of the Parts in the model if the Parent property is the Workspace.

Teleporting All Players

One can teleport all players in the game by iterating over each one of their Characters and setting the CFrame accordingly. However, you should be careful and offset the target positions so that the players' torsos do not overlap.

target = CFrame.new(0, 50, 0) --could be near a brick or in a new area
for i, player in ipairs(game.Players:GetChildren()) do
	player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
	--add an offset of 5 for each character
end

The above code would teleport each player to the position (0,50,0), going up 5 for each character so they do not overlap. If you place players on top of each other, make sure the area does not have a ceiling so players aren't put on top of a building.

Teleportation Effects

You can add in fading effects by using for loops to set the Transparency of your limbs.

player = game.Players.Player --you might want to change this...
target = Vector3.new(20, 10, 20) --...and this

function fadeTo(a, b, c)
	for transparency = a, b, c do
	--go from a to b, counting by c

		for _, part in pairs(player.Character:GetChildren()) do
		--for each of the objects in the character,

			if part:IsA("BasePart") then
			--check if it's a part, and if so

				part.Transparency = transparency
				--set its transparency
			end
		end
		wait(0.1)
	end
end

fadeTo(0, 1, 0.1) --fade out,
player.Character.Torso.CFrame = target --teleport the player
fadeTo(1, 0, -0.1) --fade back in

Other effects may include making the player rise up off the ground, become shiny by changing Reflectance, or spin using BodyAngularVelocities.