Teleportation Ability

Hello fellow devs!
I wanted to make a Teleport Ability for my game. I wanted the ability to have the following characteristics:
-Tool activated before teleport
-[Enum.KeyCode] or Click on mobile to teleport with cooldown
-Max Range is like 1k studs
-Cool effect before teleporting
(btw not asking for vfx, just an idea script I can def. implement and build on into my game. It would be helpful though :slight_smile: )

I did look at some tutorials and got some background information. I think that maybe raycasting and some other useful tools can be used here :person_shrugging:

Thanks for all the help!

2 Likes
  • Cross out Raycasting
  • Take a look at mouse.Hit and use Vector3 to get position
  • The only essential values you need to change is either of the following two: humanoidRootPart.Position or the player model’s position
1 Like

I’m not the best at scipting with characters or mouse, but can u show me an example of just a sniplet?
I really am concerned about the fact that players can just teleport so far away in an open area. :smiley:
Thanks

You can do the following for your concerns on distance teleportation:

  1. Square boundary
    Calculate value of X Y Z separately of target position minus the value of X Y Z separately of player’s position and perform math.abs on each result. If one of them is over the studs, the script may return preventing the teleportation from being performed.
  2. Radius
(vector3_1 - vector3_2).Magnitude

The formula above provides the distance between two Vector3 positions in a single stud variable. If the distance is over the amount of studs expected, the script may return preventing the teleportation from being performed.

3 Likes

So,
I took my time reading about mouse and its methods. I did especially look at Mouse.Hit() and it gives a CFrame back. Now there are like these other methods of Mouse like Mouse.Origin Mouse.UnitRay
What are the differences and how can I use Mouse.Hit to verify that the hit is a object or terrain and not just air?
I also want to know how I can like make a character tween into transparency and then teleport and instantly come back. Should I just tween the rootpart or the entire character in a for loop?
Thanks for the help!

To verify the mouse is on a part, you can check if Mouse.Target returns a part.

To make your character transparent, use TweenService in a ‘for i,v in Character:GetChildren() do’ loop, verify the child is a part with :IsA(“BasePart”). Luckily TweenService has an option to reverse the tween after it finishes (Check TweenInfo documentation), so you could wait the tween time, CFrame the character and it should come back automatically.

2 Likes

And what about terrain?
This does cast an internal ray so it might have the same properties and returning objects as a normal raycast.

You can verify if the instance clicked isA("Terrain")

Thanks, I found a solution to this.
Aparantly terrain is counted inside base parts so it works now
Thanks guys! :smiley:

1 Like