|
| 15 Feb 2015 06:50 PM |
What I want is to make a door that when you stand close to it, press E, it executes a pre-defined function. for example:
Player 1 walks up to the door, has a distance of 5 or less to the door, and presses E, he gets teleported far away. He presses E again, nothing happens.
Player 2 walks up to the door and does the same process. The same effect happens to Player 2 as to Player 1.
I have absolutely no clue how to do the magnitude/switching part of the script. I do have this:
mouse = player:GetMouse()
if statement for when the nearest players is 5 or less studs away from the door
mouse.KeyDown:connect(function(key) key = key:lower() if key=="e" then player.Character.Torso.CFrame = workspace["pos1"].CFrame.Vector3.new(0,5.5,0) end end)
|
|
|
| Report Abuse |
|
|
|
| 15 Feb 2015 06:52 PM |
| (door.Position-workspace.Eternalfireeater.Torso.Position).magnitude |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2015 07:05 PM |
@Eternalflamer Why not explain
@OP magnitude is the name for vector distance. We would find the distance between point a and b by drawing a triangle between point A and B.
|\ | \ |A \C |___\ B
The top acute angle represents your destination. The bottom right acute represents your position.
Using the Pythagorean theorem, you can calculate the hypotenuse. The forumla is C^2=A^2+B^2
Which you would solve it like this... local Distance = math.sqrt(A*A+B*B) or local Distance = math.sqrt(math.pow(A,2)+math.pow(B,2))
You need to subtract two vectors from eachother to get the vector you will use.
local Point_A = Vector3.new(5,5,5) local Point_B = Vector3.new(5,6,5)
local Point = Point_A - Point_B
local Distance = math.sqrt(Point.X*Point.X+Point.Y*Point.Y+Point.Z*Point.Z)
You will need to call math.abs() to make this a non-negative number because thats what it is.
OR
you can simply type...
local Distance = (Point_A - Point_B).magnitude |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2015 07:07 PM |
Make part's in the workspace called "Doors", the script will do the rest.
local Player = game:service'Players'.LocalPlayer local Mouse = Player:GetMouse();
local Character = Player.Character local Humanoid = Character:WaitForChild( 'Humanoid' ); local Torso = Character:WaitForChild( 'Torso' );
local Doors = { } local KeyActivation = 'e' local Trials = 0 local MaxDistanceFromDoors = 5
for i,v in next, workspace:GetChildren() do if v.Name == 'Door' then table.insert( Doors, v ) end end local function TeleportPlayer() Torso.CFrame = workspace["pos1"].CFrame * CFrame.new(0, Torso.Size.Y, 0) end
Mouse.KeyDown:connect(function( Key ) if Key == KeyActivation then Trials = Trials + 1 if Trials <= 1 then for i,v in next, Doors do if (Torso.CFrame.p - v.CFrame.p).magnitude <= MaxDistanceFromDoors then TeleportPlayer() end end end end end) |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2015 08:23 PM |
I figured these things, but how do I solve that the script always lets only YOU do it, and not the next player?
The problem is that I need the every player able to do it. |
|
|
| Report Abuse |
|
|
lsp425
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 603 |
|
|
| 15 Feb 2015 09:16 PM |
| Have it so that it loops through all the players. |
|
|
| Report Abuse |
|
|
| |
|